Merge pull request #4350 from alangpierce/upstream-fix-generated-close-curly-location

Include generated } tokens when fixing closing token positions
This commit is contained in:
Simon Lydell
2016-10-31 07:54:24 +01:00
committed by GitHub
3 changed files with 24 additions and 2 deletions

View File

@@ -376,7 +376,7 @@
Rewriter.prototype.fixOutdentLocationData = function() {
return this.scanTokens(function(token, i, tokens) {
var prevLocationData;
if (!(token[0] === 'OUTDENT' || (token.generated && token[0] === 'CALL_END'))) {
if (!(token[0] === 'OUTDENT' || (token.generated && token[0] === 'CALL_END') || (token.generated && token[0] === '}'))) {
return 1;
}
prevLocationData = tokens[i - 1][2];

View File

@@ -375,7 +375,8 @@ class exports.Rewriter
fixOutdentLocationData: ->
@scanTokens (token, i, tokens) ->
return 1 unless token[0] is 'OUTDENT' or
(token.generated and token[0] is 'CALL_END')
(token.generated and token[0] is 'CALL_END') or
(token.generated and token[0] is '}')
prevLocationData = tokens[i - 1][2]
token[2] =
first_line: prevLocationData.last_line

View File

@@ -515,6 +515,27 @@ test "Verify OUTDENT and CALL_END tokens are located at the end of the previous
eq token[0], 'CALL_END'
assertAtCloseCurly(token)
test "Verify generated } tokens are located at the end of the previous token", ->
source = '''
a(b, ->
c: () ->
if d
e
)
'''
tokens = CoffeeScript.tokens source
[..., identifier, outdent1, outdent2, closeCurly, outdent3, callEnd,
terminator] = tokens
eq identifier[0], 'IDENTIFIER'
assertAtIdentifier = (token) ->
eq token[2].first_line, identifier[2].last_line
eq token[2].first_column, identifier[2].last_column
eq token[2].last_line, identifier[2].last_line
eq token[2].last_column, identifier[2].last_column
for token in [outdent1, outdent2, closeCurly, outdent3]
assertAtIdentifier(token)
test "Verify real CALL_END tokens have the right position", ->
source = '''
a()