mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
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:
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user