Skip to content

Commit 69521b9

Browse files
helixbassGeoffreyBooth
authored andcommitted
AST: comment after semicolon (#5257)
* astNode() * no override ast() * add suggested comments * astInitialize() * astAddReturns() * separate step * recognize quoted constructor * add params to scope * object colon location data * mark generated JSX tokens * more generated tokens * preserve comment after semicolon * move comments * Add explanation for token seeming mismatch
1 parent c7e538a commit 69521b9

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/coffeescript/rewriter.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rewriter.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ exports.Rewriter = class Rewriter
576576
(token.generated and token[0] is 'CALL_END' and not token.data?.closingTagNameToken) or
577577
(token.generated and token[0] is '}')
578578
isIndent = token[0] is 'INDENT'
579-
prevToken = tokens[i - 1]
579+
prevToken = token.prevToken ? tokens[i - 1]
580580
prevLocationData = prevToken[2]
581581
# addLocationDataToGeneratedTokens() set the outdent’s location data
582582
# to the preceding token’s, but in order to detect comments inside an
@@ -685,6 +685,9 @@ exports.Rewriter = class Rewriter
685685
tokens.splice i, 1, @indentation()...
686686
return 1
687687
if @tag(i + 1) in EXPRESSION_CLOSE
688+
if token[1] is ';' and @tag(i + 1) is 'OUTDENT'
689+
tokens[i + 1].prevToken = token
690+
moveComments token, tokens[i + 1]
688691
tokens.splice i, 1
689692
return 0
690693
if tag is 'CATCH'

test/abstract_syntax_tree.coffee

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,6 +4255,15 @@ test "AST as expected for comments", ->
42554255
value: '\n # multiline\n # indented here comment\n '
42564256
]
42574257

4258+
testComments '''
4259+
if foo
4260+
;
4261+
### empty ###
4262+
''', [
4263+
type: 'CommentBlock'
4264+
value: ' empty '
4265+
]
4266+
42584267
test "AST as expected for chained comparisons", ->
42594268
testExpression '''
42604269
a < b < c

0 commit comments

Comments
 (0)