Skip to content

Instantly share code, notes, and snippets.

@rattrayalex
Created August 15, 2016 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rattrayalex/53c06ca5026841dc206ca97589246023 to your computer and use it in GitHub Desktop.
Save rattrayalex/53c06ca5026841dc206ca97589246023 to your computer and use it in GitHub Desktop.
diff --git a/src/grammar.coffee b/src/grammar.coffee
index 4ff9a1c..7229664 100644
--- a/src/grammar.coffee
+++ b/src/grammar.coffee
@@ -365,7 +365,7 @@ grammar =
Export: [
o 'EXPORT Class', -> new Export $2
- o 'EXPORT Identifier = Expression', -> new Export new Assign($2, $4)
+ o 'EXPORT Identifier = Expression', -> new Export new Assign($2, $4, 'export')
o 'EXPORT DEFAULT Expression', -> new ExportDefault $3
o 'EXPORT ExportImportClause', -> new ExportImport $2
o 'EXPORT ExportImportClause FROM String', -> new ExportImport $2, $4
diff --git a/src/nodes.coffee b/src/nodes.coffee
index ec646d9..fcc1b61 100644
--- a/src/nodes.coffee
+++ b/src/nodes.coffee
@@ -1323,6 +1323,8 @@ exports.ModuleIdentifier = class ModuleIdentifier extends Base
children: ['original', 'alias']
compileNode: (o) ->
+ variableName = @alias.value or @original.value
+ o.scope.add variableName, 'import'
code = []
code.push @makeCode @original.value
code.push @makeCode " as #{@alias.value}" if @alias?
@@ -1368,20 +1370,18 @@ exports.Assign = class Assign extends Base
@value.klass = new Value @variable.base, properties
@value.name = name
@value.variable = @variable
- unless @context
+ if not @context or @context is 'export'
varBase = @variable.unwrapAll()
unless varBase.isAssignable()
@variable.error "'#{@variable.compile o}' can't be assigned"
unless varBase.hasProperties?()
- insideModuleStatement = no
- for expression in o.scope.expressions.expressions
- if expression instanceof Import or expression instanceof Export or expression instanceof ExportImport # But *not* ExportDefault
- insideModuleStatement = yes
- unless insideModuleStatement
- if @param
- o.scope.add varBase.value, 'var'
- else
- o.scope.find varBase.value
+ if @context is 'export'
+ o.scope.add varBase.value, 'export'
+ if @param
+ o.scope.add varBase.value, 'var'
+ else
+ o.scope.find varBase.value
+
val = @value.compileToFragments o, LEVEL_LIST
@variable.front = true if isValue and @variable.base instanceof Obj
compiledName = @variable.compileToFragments o, LEVEL_LIST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment