Skip to content

Commit

Permalink
fix #3909 (#4861)
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenko authored and GeoffreyBooth committed Jan 28, 2018
1 parent 0217ed5 commit 74bd537
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/coffeescript/lexer.js

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

4 changes: 3 additions & 1 deletion src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ exports.Lexer = class Lexer
return 0 unless match = MULTI_DENT.exec chunk
indent = match[0]

@seenFor = no
prev = @prev()
backslash = prev? and prev[0] is '\\'
@seenFor = no unless backslash and @seenFor
@seenImport = no unless @importSpecifierList
@seenExport = no unless @exportSpecifierList

Expand Down
115 changes: 115 additions & 0 deletions test/control_flow.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,118 @@ test "#3441: `StatementLiteral` in parentheses", ->

r9 = for a in arr then (a; continue)
arrayEq r9, []

# Issue #3909: backslash to break line in `for` loops throw syntax error
test "#3909: backslash `for own ... of`", ->

obj = {a: 1, b: 2, c: 3}
arr = ['a', 'b', 'c']

x1 \
= ( key for own key of obj )
arrayEq x1, arr

x2 = \
( key for own key of obj )
arrayEq x2, arr

x3 = ( \
key for own key of obj )
arrayEq x3, arr

x4 = ( key \
for own key of obj )
arrayEq x4, arr

x5 = ( key for own key of \
obj )
arrayEq x5, arr

x6 = ( key for own key of obj \
)
arrayEq x6, arr

x7 = ( key for \
own key of obj )
arrayEq x7, arr

x8 = ( key for own \
key of obj )
arrayEq x8, arr

x9 = ( key for own key \
of obj )
arrayEq x9, arr


test "#3909: backslash `for ... of`", ->
obj = {a: 1, b: 2, c: 3}
arr = ['a', 'b', 'c']

x1 \
= ( key for key of obj )
arrayEq x1, arr

x2 = \
( key for key of obj )
arrayEq x2, arr

x3 = ( \
key for key of obj )
arrayEq x3, arr

x4 = ( key \
for key of obj )
arrayEq x4, arr

x5 = ( key for key of \
obj )
arrayEq x5, arr

x6 = ( key for key of obj \
)
arrayEq x6, arr

x7 = ( key for \
key of obj )
arrayEq x7, arr

x8 = ( key for key \
of obj )
arrayEq x8, arr


test "#3909: backslash `for ... in`", ->
arr = ['a', 'b', 'c']

x1 \
= ( key for key in arr )
arrayEq x1, arr

x2 = \
( key for key in arr )
arrayEq x2, arr

x3 = ( \
key for key in arr )
arrayEq x3, arr

x4 = ( key \
for key in arr )
arrayEq x4, arr

x5 = ( key for key in \
arr )
arrayEq x5, arr

x6 = ( key for key in arr \
)
arrayEq x6, arr

x7 = ( key for \
key in arr )
arrayEq x7, arr

x8 = ( key for key \
in arr )
arrayEq x8, arr

0 comments on commit 74bd537

Please sign in to comment.