Skip to content

Commit 4a4f752

Browse files
Fix #3098: Suppressed newline should be unsuppressed by semicolon (#4669)
1 parent b20e52d commit 4a4f752

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

lib/coffeescript/lexer.js

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

src/lexer.coffee

+8-2
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ exports.Lexer = class Lexer
509509
@token 'OUTDENT', moveOut, 0, outdentLength
510510
moveOut -= dent
511511
@outdebt -= moveOut if dent
512-
@tokens.pop() while @value() is ';'
512+
@suppressSemicolons()
513513

514514
@token 'TERMINATOR', '\n', outdentLength, 0 unless @tag() is 'TERMINATOR' or noNewlines
515515
@indent = decreasedIndent
@@ -527,7 +527,7 @@ exports.Lexer = class Lexer
527527

528528
# Generate a newline token. Consecutive newlines get merged together.
529529
newlineToken: (offset) ->
530-
@tokens.pop() while @value() is ';'
530+
@suppressSemicolons()
531531
@token 'TERMINATOR', '\n', offset, 0 unless @tag() is 'TERMINATOR'
532532
this
533533

@@ -662,6 +662,7 @@ exports.Lexer = class Lexer
662662
@exportSpecifierList = no
663663

664664
if value is ';'
665+
@error 'unexpected ;' if prev?[0] in ['=', UNFINISHED...]
665666
@seenFor = @seenImport = @seenExport = no
666667
tag = 'TERMINATOR'
667668
else if value is '*' and prev?[0] is 'EXPORT'
@@ -1053,6 +1054,11 @@ exports.Lexer = class Lexer
10531054
when other then (if options.double then "\\#{other}" else other)
10541055
"#{options.delimiter}#{body}#{options.delimiter}"
10551056

1057+
suppressSemicolons: ->
1058+
while @value() is ';'
1059+
@tokens.pop()
1060+
@error 'unexpected ;' if @prev()?[0] in ['=', UNFINISHED...]
1061+
10561062
# Throws an error at either a given offset from the current chunk or at the
10571063
# location of a token (`token[2]`).
10581064
error: (message, options = {}) ->

test/error_messages.coffee

+9
Original file line numberDiff line numberDiff line change
@@ -1759,3 +1759,12 @@ test "#3199: error message for throw indented comprehension", ->
17591759
x for x in [1, 2, 3]
17601760
^
17611761
'''
1762+
1763+
test "#3098: suppressed newline should be unsuppressed by semicolon", ->
1764+
assertErrorFormat '''
1765+
a = ; 5
1766+
''', '''
1767+
[stdin]:1:5: error: unexpected ;
1768+
a = ; 5
1769+
^
1770+
'''

0 commit comments

Comments
 (0)