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

Fix #4451: Treat default as a keyword in an export statement only when it follows export or as

This commit is contained in:
Geoffrey Booth 2017-04-02 17:36:25 -07:00
parent ca0fd229e1
commit 98d1644c5b
3 changed files with 15 additions and 7 deletions

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, tag, tagToken;
var alias, colon, colonOffset, id, idLength, input, match, poppedToken, prev, ref2, ref3, ref4, ref5, ref6, ref7, ref8, tag, tagToken;
if (!(match = IDENTIFIER.exec(this.chunk))) {
return 0;
}
@ -99,15 +99,15 @@
this.token('AS', id);
return id.length;
}
if (id === 'default' && this.seenExport) {
if (id === 'default' && this.seenExport && ((ref4 = this.tag()) === 'EXPORT' || ref4 === 'AS')) {
this.token('DEFAULT', id);
return id.length;
}
ref4 = this.tokens, prev = ref4[ref4.length - 1];
tag = colon || (prev != null) && (((ref5 = prev[0]) === '.' || ref5 === '?.' || ref5 === '::' || ref5 === '?::') || !prev.spaced && prev[0] === '@') ? 'PROPERTY' : 'IDENTIFIER';
ref5 = this.tokens, prev = ref5[ref5.length - 1];
tag = colon || (prev != null) && (((ref6 = prev[0]) === '.' || ref6 === '?.' || ref6 === '::' || ref6 === '?::') || !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' && (ref6 = this.tag(), indexOf.call(LINE_BREAK, ref6) >= 0)) {
if (tag === 'WHEN' && (ref7 = this.tag(), indexOf.call(LINE_BREAK, ref7) >= 0)) {
tag = 'LEADING_WHEN';
} else if (tag === 'FOR') {
this.seenFor = true;
@ -172,7 +172,7 @@
tagToken.origin = [tag, alias, tagToken[2]];
}
if (poppedToken) {
ref7 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = ref7[0], tagToken[2].first_column = ref7[1];
ref8 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = ref8[0], tagToken[2].first_column = ref8[1];
}
if (colon) {
colonOffset = input.lastIndexOf(':');

View file

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

View file

@ -749,3 +749,11 @@ test "#4394: export shouldn't prevent variable declarations", ->
};
"""
eq toJS(input), output
test "#4451: `default` in an export statement is only treated as a keyword when it follows `export` or `as`", ->
input = "export default { default: 1 }"
output = """
export default {
"default": 1
};
"""