1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fix #4481: Export an imported member named default

This commit is contained in:
Geoffrey Booth 2017-04-02 17:56:51 -07:00
parent 98d1644c5b
commit dde7b0d98a
6 changed files with 129 additions and 107 deletions

View file

@ -395,6 +395,8 @@
return new ExportSpecifier($1, new Literal($3));
}), o('DEFAULT', function() {
return new ExportSpecifier(new Literal($1));
}), o('DEFAULT AS Identifier', function() {
return new ExportSpecifier(new Literal($1), $3);
})
],
Invocation: [

View file

@ -69,7 +69,7 @@
};
Lexer.prototype.identifierToken = function() {
var alias, colon, colonOffset, id, idLength, input, match, poppedToken, prev, ref2, ref3, ref4, ref5, ref6, ref7, ref8, tag, tagToken;
var alias, colon, colonOffset, id, idLength, input, match, poppedToken, prev, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, tag, tagToken;
if (!(match = IDENTIFIER.exec(this.chunk))) {
return 0;
}
@ -95,19 +95,19 @@
return id.length;
}
}
if (id === 'as' && this.seenExport && this.tag() === 'IDENTIFIER') {
if (id === 'as' && this.seenExport && ((ref4 = this.tag()) === 'IDENTIFIER' || ref4 === 'DEFAULT')) {
this.token('AS', id);
return id.length;
}
if (id === 'default' && this.seenExport && ((ref4 = this.tag()) === 'EXPORT' || ref4 === 'AS')) {
if (id === 'default' && this.seenExport && ((ref5 = this.tag()) === 'EXPORT' || ref5 === 'AS')) {
this.token('DEFAULT', id);
return id.length;
}
ref5 = this.tokens, prev = ref5[ref5.length - 1];
tag = colon || (prev != null) && (((ref6 = prev[0]) === '.' || ref6 === '?.' || ref6 === '::' || ref6 === '?::') || !prev.spaced && prev[0] === '@') ? 'PROPERTY' : 'IDENTIFIER';
ref6 = this.tokens, prev = ref6[ref6.length - 1];
tag = colon || (prev != null) && (((ref7 = prev[0]) === '.' || ref7 === '?.' || ref7 === '::' || ref7 === '?::') || !prev.spaced && prev[0] === '@') ? 'PROPERTY' : 'IDENTIFIER';
if (tag === 'IDENTIFIER' && (indexOf.call(JS_KEYWORDS, id) >= 0 || indexOf.call(COFFEE_KEYWORDS, id) >= 0) && !(this.exportSpecifierList && indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
tag = id.toUpperCase();
if (tag === 'WHEN' && (ref7 = this.tag(), indexOf.call(LINE_BREAK, ref7) >= 0)) {
if (tag === 'WHEN' && (ref8 = this.tag(), indexOf.call(LINE_BREAK, ref8) >= 0)) {
tag = 'LEADING_WHEN';
} else if (tag === 'FOR') {
this.seenFor = true;
@ -172,7 +172,7 @@
tagToken.origin = [tag, alias, tagToken[2]];
}
if (poppedToken) {
ref8 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = ref8[0], tagToken[2].first_column = ref8[1];
ref9 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = ref9[0], tagToken[2].first_column = ref9[1];
}
if (colon) {
colonOffset = input.lastIndexOf(':');

File diff suppressed because one or more lines are too long

View file

@ -412,6 +412,7 @@ grammar =
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
o 'DEFAULT AS Identifier', -> new ExportSpecifier new Literal($1), $3
]
# Ordinary function invocation, or a chained series of calls.

View file

@ -124,7 +124,7 @@ exports.Lexer = class Lexer
if @tag() in ['DEFAULT', 'IMPORT_ALL', 'IDENTIFIER']
@token 'AS', id
return id.length
if id is 'as' and @seenExport and @tag() is 'IDENTIFIER'
if id is 'as' and @seenExport and @tag() in ['IDENTIFIER', 'DEFAULT']
@token 'AS', id
return id.length
if id is 'default' and @seenExport and @tag() in ['EXPORT', 'AS']

View file

@ -718,7 +718,7 @@ test "export an aliased member named default", ->
};"""
eq toJS(input), output
test "export an imported member named default", ->
test "import an imported member named default", ->
input = "import { default } from 'lib'"
output = """
import {
@ -726,7 +726,7 @@ test "export an imported member named default", ->
} from 'lib';"""
eq toJS(input), output
test "export an imported aliased member named default", ->
test "import an imported aliased member named default", ->
input = "import { default as def } from 'lib'"
output = """
import {
@ -734,6 +734,22 @@ test "export an imported aliased member named default", ->
} from 'lib';"""
eq toJS(input), output
test "export an imported member named default", ->
input = "export { default } from 'lib'"
output = """
export {
default
} from 'lib';"""
eq toJS(input), output
test "export an imported aliased member named default", ->
input = "export { default as def } from 'lib'"
output = """
export {
default as def
} from 'lib';"""
eq toJS(input), output
test "#4394: export shouldn't prevent variable declarations", ->
input = """
x = 1