Skip to content

Commit aca72f9

Browse files
authored
Merge pull request #4350 from alangpierce/upstream-fix-generated-close-curly-location
Include generated } tokens when fixing closing token positions
2 parents 0d13231 + c5afb4e commit aca72f9

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/coffee-script/rewriter.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rewriter.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ class exports.Rewriter
375375
fixOutdentLocationData: ->
376376
@scanTokens (token, i, tokens) ->
377377
return 1 unless token[0] is 'OUTDENT' or
378-
(token.generated and token[0] is 'CALL_END')
378+
(token.generated and token[0] is 'CALL_END') or
379+
(token.generated and token[0] is '}')
379380
prevLocationData = tokens[i - 1][2]
380381
token[2] =
381382
first_line: prevLocationData.last_line

test/location.coffee

+21
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,27 @@ test "Verify OUTDENT and CALL_END tokens are located at the end of the previous
515515
eq token[0], 'CALL_END'
516516
assertAtCloseCurly(token)
517517

518+
test "Verify generated } tokens are located at the end of the previous token", ->
519+
source = '''
520+
a(b, ->
521+
c: () ->
522+
if d
523+
e
524+
)
525+
'''
526+
tokens = CoffeeScript.tokens source
527+
[..., identifier, outdent1, outdent2, closeCurly, outdent3, callEnd,
528+
terminator] = tokens
529+
eq identifier[0], 'IDENTIFIER'
530+
assertAtIdentifier = (token) ->
531+
eq token[2].first_line, identifier[2].last_line
532+
eq token[2].first_column, identifier[2].last_column
533+
eq token[2].last_line, identifier[2].last_line
534+
eq token[2].last_column, identifier[2].last_column
535+
536+
for token in [outdent1, outdent2, closeCurly, outdent3]
537+
assertAtIdentifier(token)
538+
518539
test "Verify real CALL_END tokens have the right position", ->
519540
source = '''
520541
a()

0 commit comments

Comments
 (0)