Skip to content

Allow yield indented object #5072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2018
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
10 changes: 10 additions & 0 deletions lib/coffeescript/grammar.js

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

418 changes: 211 additions & 207 deletions lib/coffeescript/parser.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/grammar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ grammar =
Yield: [
o 'YIELD', -> new Op $1, new Value new Literal ''
o 'YIELD Expression', -> new Op $1, $2
o 'YIELD INDENT Object OUTDENT', -> new Op $1, $3
o 'YIELD FROM Expression', -> new Op $1.concat($2), $3
]

Expand Down Expand Up @@ -817,7 +818,8 @@ grammar =
o '- Expression', (-> new Op '-', $2), prec: 'UNARY_MATH'
o '+ Expression', (-> new Op '+', $2), prec: 'UNARY_MATH'

o 'AWAIT Expression', -> new Op $1 , $2
o 'AWAIT Expression', -> new Op $1, $2
o 'AWAIT INDENT Object OUTDENT', -> new Op $1, $3

o '-- SimpleAssignable', -> new Op '--', $2
o '++ SimpleAssignable', -> new Op '++', $2
Expand Down
8 changes: 8 additions & 0 deletions test/async.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,11 @@ test "async methods in classes", ->

eq await Child.static(), 1
eq await new Child().method(), 2

test "#3199: await multiline implicit object", ->
do ->
y =
if no then await
type: 'a'
msg: 'b'
eq undefined, y
44 changes: 44 additions & 0 deletions test/error_messages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,50 @@ test "#3199: error message for throw indented comprehension", ->
^
'''

test "#3199: error message for yield indented non-object", ->
assertErrorFormat '''
->
yield
1
''', '''
[stdin]:3:5: error: unexpected number
1
^
'''

test "#3199: error message for yield indented comprehension", ->
assertErrorFormat '''
->
yield
x for x in [1, 2, 3]
''', '''
[stdin]:3:5: error: unexpected identifier
x for x in [1, 2, 3]
^
'''

test "#3199: error message for await indented non-object", ->
assertErrorFormat '''
->
await
1
''', '''
[stdin]:3:5: error: unexpected number
1
^
'''

test "#3199: error message for await indented comprehension", ->
assertErrorFormat '''
->
await
x for x in [1, 2, 3]
''', '''
[stdin]:3:5: error: unexpected identifier
x for x in [1, 2, 3]
^
'''

test "#3098: suppressed newline should be unsuppressed by semicolon", ->
assertErrorFormat '''
a = ; 5
Expand Down
16 changes: 16 additions & 0 deletions test/formatting.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,22 @@ test "#3199: throw multiline implicit object", ->
msg: 'b'
eq undefined, y

y = do ->
yield
type: 'a'
msg: 'b'

if no then yield
type: 'c'
msg: 'd'

1
{value, done} = y.next()
ok value.type is 'a' and done is no

{value, done} = y.next()
ok value is 1 and done is yes

test "#4576: multiple row function chaining", ->
->
eq @a, 3
Expand Down