Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we not want = in UNFINISHED?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe the other way around: what does adding in UNFINISHED fixes, given that prev?[0] is '=' is the relevant fix here? Same in suppressSemicolons.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #3098 (comment)

UNFINISHED covers all the similar tokens like += etc. I think @jashkenas in his comment was worried about the special cases around =, like =(newline)(object literal).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, putting = into UNFINISHED causes tests to fail.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. LGTM then.

@seenFor = @seenImport = @seenExport = no
tag = 'TERMINATOR'
else if value is '*' and prev?[0] is 'EXPORT'
Expand Down Expand Up @@ -1053,6 +1054,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
^
'''