Skip to content

Commit 2a0f178

Browse files
committed
Follow the example of Class and create a new expression for Import
1 parent 141ec77 commit 2a0f178

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/grammar.coffee

+7-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ grammar =
117117
o 'Class'
118118
o 'Throw'
119119
o 'Yield'
120+
o 'Import'
121+
o 'Export'
120122
]
121123

122124
Yield: [
@@ -349,6 +351,10 @@ grammar =
349351
o 'CLASS SimpleAssignable EXTENDS Expression Block', -> new Class $2, $4, $5
350352
]
351353

354+
Import: [
355+
o 'IMPORT Expression', -> new Import $2
356+
]
357+
352358
# Ordinary function invocation, or a chained series of calls.
353359
Invocation: [
354360
o 'Value OptFuncExist Arguments', -> new Call $1, $3, $2
@@ -644,7 +650,7 @@ operators = [
644650
['right', 'YIELD']
645651
['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN', 'THROW', 'EXTENDS']
646652
['right', 'FORIN', 'FOROF', 'BY', 'WHEN']
647-
['right', 'IF', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS']
653+
['right', 'IF', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'IMPORT', 'EXPORT']
648654
['left', 'POST_IF']
649655
]
650656

src/nodes.coffee

+16
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,22 @@ exports.Class = class Class extends Base
12231223
klass = new Assign @variable, klass if @variable
12241224
klass.compileToFragments o
12251225

1226+
#### Import
1227+
1228+
exports.Import = class Import extends Base
1229+
constructor: (@expression) ->
1230+
1231+
children: ['expression']
1232+
1233+
isStatement: YES
1234+
jumps: NO
1235+
1236+
makeReturn: THIS
1237+
1238+
compileNode: (o) ->
1239+
[].concat @makeCode(@tab + 'import '), @expression.compileToFragments(o), @makeCode(';')
1240+
1241+
12261242
#### Assign
12271243

12281244
# The **Assign** is used to assign a local variable to value, or to set the

0 commit comments

Comments
 (0)