Skip to content

Commit

Permalink
Fix jashkenas#3098: Suppressed newline should be unsuppressed by semi…
Browse files Browse the repository at this point in the history
…colon
  • Loading branch information
GeoffreyBooth committed Aug 30, 2017
1 parent e54b8a1 commit a93368a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
31 changes: 22 additions & 9 deletions lib/coffeescript/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ exports.Lexer = class Lexer
@token 'OUTDENT', moveOut, 0, outdentLength
moveOut -= dent
@outdebt -= moveOut if dent
@tokens.pop() while @value() is ';'
@suppressSemicolons()

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

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

Expand Down Expand Up @@ -662,6 +662,7 @@ exports.Lexer = class Lexer
@exportSpecifierList = no

if value is ';'
@error 'unexpected ;' if prev?[0] in ['=', UNFINISHED...]
@seenFor = @seenImport = @seenExport = no
tag = 'TERMINATOR'
else if value is '*' and prev?[0] is 'EXPORT'
Expand Down Expand Up @@ -1052,6 +1053,11 @@ exports.Lexer = class Lexer
when other then (if options.double then "\\#{other}" else other)
"#{options.delimiter}#{body}#{options.delimiter}"

suppressSemicolons: ->
while @value() is ';'
@tokens.pop()
@error 'unexpected ;' if @prev()?[0] in ['=', UNFINISHED...]

# Throws an error at either a given offset from the current chunk or at the
# location of a token (`token[2]`).
error: (message, options = {}) ->
Expand Down
9 changes: 9 additions & 0 deletions test/error_messages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1759,3 +1759,12 @@ test "#3199: error message for throw indented comprehension", ->
x for x in [1, 2, 3]
^
'''

test "#3098: suppressed newline should be unsuppressed by semicolon", ->
assertErrorFormat '''
a = ; 5
''', '''
[stdin]:1:5: error: unexpected ;
a = ; 5
^
'''

0 comments on commit a93368a

Please sign in to comment.