Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/coffee-script/grammar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

227 changes: 118 additions & 109 deletions lib/coffee-script/parser.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/grammar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
48 changes: 48 additions & 0 deletions test/modules.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -685,3 +685,51 @@ test "default and wrapped members can be imported multiple times if aliased", ->
foo as bar
} from 'lib';"""
eq toJS(input), output

test "import a member named default", ->
input = "import { default } from 'lib'"
output = """
import {
default
} from 'lib';"""
eq toJS(input), output

test "import an aliased member named default", ->
input = "import { default as def } from 'lib'"
output = """
import {
default as def
} from 'lib';"""
eq toJS(input), output

test "export a member named default", ->
input = "export { default }"
output = """
export {
default
};"""
eq toJS(input), output

test "export an aliased member named default", ->
input = "export { def as default }"
output = """
export {
def as default
};"""
eq toJS(input), output

test "export an imported member named default", ->
input = "import { default } from 'lib'"
output = """
import {
default
} from 'lib';"""
eq toJS(input), output

test "export an imported aliased member named default", ->
input = "import { default as def } from 'lib'"
output = """
import {
default as def
} from 'lib';"""
eq toJS(input), output