Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit570191f

Browse files
committed
Consolidate Import and Export classes together
1 parentafae27b commit570191f

File tree

2 files changed

+30
-49
lines changed

2 files changed

+30
-49
lines changed

‎src/grammar.coffee

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ grammar =
352352
]
353353

354354
Import: [
355-
o'IMPORT String',->newImportnull, $2
356-
o'IMPORT ImportClause IMPORT_FROM String',->newImport $2, $4
355+
o'IMPORT String',->newModule'import',null,no, $2
356+
o'IMPORT ImportClause IMPORT_FROM String',->newModule'import', $2,no, $4
357357
]
358358

359359
ImportClause: [
@@ -363,6 +363,17 @@ grammar =
363363
o'{ ModuleList OptComma }',->newModuleList $2,yes
364364
]
365365

366+
Export: [
367+
o'EXPORT ExportClause',->newModule'export', $2
368+
o'EXPORT EXPORT_DEFAULT Expression',->newModule'export', $3,yes
369+
o'EXPORT ExportClause IMPORT_FROM String',->newModule'export', $2,no, $4
370+
]
371+
372+
ExportClause: [
373+
o'IMPORT_ALL',->newLiteral $1
374+
o'{ ModuleList OptComma }',->newModuleList $2,yes
375+
]
376+
366377
ModuleList: [
367378
o'ModuleIdentifier',-> [$1]
368379
o'ModuleList , ModuleIdentifier',->$1.concat $3
@@ -380,17 +391,6 @@ grammar =
380391
o'Identifier EXPORT_AS EXPORT_DEFAULT',->newModuleIdentifier $1,newLiteral($3)
381392
]
382393

383-
Export: [
384-
o'EXPORT ExportClause',->newExport $2
385-
o'EXPORT EXPORT_DEFAULT Expression',->newExport $3,yes
386-
o'EXPORT ExportClause IMPORT_FROM String',->newExport $2,no, $4
387-
]
388-
389-
ExportClause: [
390-
o'IMPORT_ALL',->newLiteral $1
391-
o'{ ModuleList OptComma }',->newModuleList $2,yes
392-
]
393-
394394
# Ordinary function invocation, or a chained series of calls.
395395
Invocation: [
396396
o'Value OptFuncExist Arguments',->newCall $1, $3, $2

‎src/nodes.coffee

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,12 +1223,14 @@ exports.Class = class Class extends Base
12231223
klass=newAssign@variable, klassif@variable
12241224
klass.compileToFragments o
12251225

1226-
#### Import
1226+
#### Import and Export
12271227

1228-
exports.Import=classImportextendsBase
1229-
constructor: (@importClause,@moduleName,@export=no)->
1228+
exports.Module=classModuleextendsBase
1229+
constructor: (@type,@clause,@default=no,@moduleName)->
1230+
if@typeisnt'import'and@typeisnt'export'
1231+
@error'module type must be import or export'
12301232

1231-
children: ['importClause','moduleName']
1233+
children: ['clause','moduleName']
12321234

12331235
isStatement: YES
12341236
jumps: THIS
@@ -1237,13 +1239,17 @@ exports.Import = class Import extends Base
12371239
compileNode: (o)->
12381240
code= []
12391241

1240-
code.push@makeCode(@tab+ (unless@exportthen'import'else'export'))
1242+
code.push@makeCode"#{@tab}#{@type}"
12411243

1242-
if@importClause?
1243-
code.push fragmentfor fragmentin@importClause.compileNode(o)
1244-
code.push@makeCode' from'
1244+
if@default
1245+
code.push@makeCode'default'
1246+
1247+
if@clause?and@clause.lengthisnt0
1248+
code.push fragmentfor fragmentin@clause.compileNode(o)
12451249

12461250
if@moduleName?.value?
1251+
unless@typeis'import'and@clauseisnull
1252+
code.push@makeCode' from'
12471253
code.push@makeCode@moduleName.value
12481254

12491255
code.push@makeCode';'
@@ -1296,31 +1302,6 @@ exports.ModuleIdentifier = class ModuleIdentifier extends Base
12961302
code.push@makeCode" as#{@alias.value}"if@alias?
12971303
code
12981304

1299-
#### Export
1300-
1301-
exports.Export=classExportextendsBase
1302-
constructor: (@exportClause,@default=no,@moduleName)->
1303-
1304-
children: ['exportClause','moduleName']
1305-
1306-
isStatement: YES
1307-
jumps: THIS
1308-
makeReturn: THIS
1309-
1310-
compileNode: (o)->
1311-
code= []
1312-
1313-
code.push@makeCode(@tab+"export#{if@defaultthen'default'else''}")
1314-
1315-
if@exportClause?
1316-
code.push fragmentfor fragmentin@exportClause.compileNode(o)
1317-
1318-
if@moduleName?.value?
1319-
code.push@makeCode" from#{@moduleName.value}"
1320-
1321-
code.push@makeCode';'
1322-
code
1323-
13241305
#### Assign
13251306

13261307
# The **Assign** is used to assign a local variable to value, or to set the
@@ -1366,10 +1347,10 @@ exports.Assign = class Assign extends Base
13661347
unlessvarBase.isAssignable()
13671348
@variable.error"'#{@variable.compile o}' can't be assigned"
13681349
unlessvarBase.hasProperties?()
1369-
insideExport=no
1350+
insideModuleStatement=no
13701351
for expressionino.scope.expressions.expressions
1371-
insideExport=yesif expressioninstanceofExport
1372-
unlessinsideExport
1352+
insideModuleStatement=yesif expressioninstanceofModule
1353+
unlessinsideModuleStatement
13731354
if@param
13741355
o.scope.addvarBase.value,'var'
13751356
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp