Skip to content

Commit

Permalink
Added ExportDefaultSpecifier.
Browse files Browse the repository at this point in the history
For things like:
  `export name from 'module'` and
  `export name, { ... } from 'module'`
  • Loading branch information
Kronuz committed Aug 7, 2017
1 parent 3bbbbb9 commit 6b336fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
6 changes: 6 additions & 0 deletions esprima/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ def __init__(self, local, exported):
self.local = local


class ExportDefaultSpecifier(Node):
def __init__(self, local):
self.type = Syntax.ExportDefaultSpecifier
self.local = local


class ExpressionStatement(Node):
def __init__(self, expression):
self.type = Syntax.ExpressionStatement
Expand Down
28 changes: 21 additions & 7 deletions esprima/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2975,6 +2975,11 @@ def parseExportSpecifier(self):

return self.finalize(node, Node.ExportSpecifier(local, exported))

def parseExportDefaultSpecifier(self):
node = self.createNode()
local = self.parseIdentifierName()
return self.finalize(node, Node.ExportDefaultSpecifier(local))

def parseExportDeclaration(self):
if self.context.inFunctionBody:
self.throwError(Messages.IllegalExportDeclaration)
Expand Down Expand Up @@ -3053,13 +3058,22 @@ def parseExportDeclaration(self):
source = None
isExportFromIdentifier = False

self.expect('{')
while not self.match('}'):
isExportFromIdentifier = isExportFromIdentifier or self.matchKeyword('default')
specifiers.append(self.parseExportSpecifier())
if not self.match('}'):
self.expect(',')
self.expect('}')
expectSpecifiers = True
if self.lookahead.type is Token.Identifier:
specifiers.append(self.parseExportDefaultSpecifier())
if self.match(','):
self.nextToken()
else:
expectSpecifiers = False

if expectSpecifiers:
self.expect('{')
while not self.match('}'):
isExportFromIdentifier = isExportFromIdentifier or self.matchKeyword('default')
specifiers.append(self.parseExportSpecifier())
if not self.match('}'):
self.expect(',')
self.expect('}')

if self.matchContextualKeyword('from'):
# export {default} from 'foo'
Expand Down
1 change: 1 addition & 0 deletions esprima/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Syntax:
ExportDefaultDeclaration = "ExportDefaultDeclaration"
ExportNamedDeclaration = "ExportNamedDeclaration"
ExportSpecifier = "ExportSpecifier"
ExportDefaultSpecifier = "ExportDefaultSpecifier"
ExpressionStatement = "ExpressionStatement"
ForStatement = "ForStatement"
ForOfStatement = "ForOfStatement"
Expand Down

0 comments on commit 6b336fc

Please sign in to comment.