Allow imported module members to be named default

This commit is contained in:
Geoffrey Booth
2016-12-04 18:44:07 -08:00
parent fb0639fa38
commit 03eceeb615
6 changed files with 177 additions and 111 deletions

View File

@@ -372,6 +372,8 @@ grammar =
ImportSpecifier: [
o 'Identifier', -> new ImportSpecifier $1
o 'Identifier AS Identifier', -> new ImportSpecifier $1, $3
o 'DEFAULT', -> new ImportSpecifier new Literal $1
o 'DEFAULT AS Identifier', -> new ImportSpecifier new Literal($1), $3
]
ImportDefaultSpecifier: [
@@ -409,6 +411,7 @@ grammar =
o 'Identifier', -> new ExportSpecifier $1
o 'Identifier AS Identifier', -> new ExportSpecifier $1, $3
o 'Identifier AS DEFAULT', -> new ExportSpecifier $1, new Literal $3
o 'DEFAULT', -> new ExportSpecifier new Literal $1
]
# Ordinary function invocation, or a chained series of calls.

View File

@@ -121,7 +121,7 @@ exports.Lexer = class Lexer
@tokens[@tokens.length - 1][0] = 'IMPORT_ALL'
else if @value() in COFFEE_KEYWORDS
@tokens[@tokens.length - 1][0] = 'IDENTIFIER'
if @tag() in ['IMPORT_ALL', 'IDENTIFIER']
if @tag() in ['DEFAULT', 'IMPORT_ALL', 'IDENTIFIER']
@token 'AS', id
return id.length
if id is 'as' and @seenExport and @tag() is 'IDENTIFIER'