Skip to content

Commit 70f6cb7

Browse files
helixbassGeoffreyBooth
authored andcommitted
Allow yield indented object (#5072)
* allow yield indented object * allow await indented object * fixes from code review
1 parent be702d6 commit 70f6cb7

File tree

6 files changed

+292
-208
lines changed

6 files changed

+292
-208
lines changed

lib/coffeescript/grammar.js

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

lib/coffeescript/parser.js

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

src/grammar.coffee

+3-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ grammar =
138138
Yield: [
139139
o 'YIELD', -> new Op $1, new Value new Literal ''
140140
o 'YIELD Expression', -> new Op $1, $2
141+
o 'YIELD INDENT Object OUTDENT', -> new Op $1, $3
141142
o 'YIELD FROM Expression', -> new Op $1.concat($2), $3
142143
]
143144

@@ -817,7 +818,8 @@ grammar =
817818
o '- Expression', (-> new Op '-', $2), prec: 'UNARY_MATH'
818819
o '+ Expression', (-> new Op '+', $2), prec: 'UNARY_MATH'
819820

820-
o 'AWAIT Expression', -> new Op $1 , $2
821+
o 'AWAIT Expression', -> new Op $1, $2
822+
o 'AWAIT INDENT Object OUTDENT', -> new Op $1, $3
821823

822824
o '-- SimpleAssignable', -> new Op '--', $2
823825
o '++ SimpleAssignable', -> new Op '++', $2

test/async.coffee

+8
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,11 @@ test "async methods in classes", ->
196196

197197
eq await Child.static(), 1
198198
eq await new Child().method(), 2
199+
200+
test "#3199: await multiline implicit object", ->
201+
do ->
202+
y =
203+
if no then await
204+
type: 'a'
205+
msg: 'b'
206+
eq undefined, y

test/error_messages.coffee

+44
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,50 @@ test "#3199: error message for throw indented comprehension", ->
17961796
^
17971797
'''
17981798

1799+
test "#3199: error message for yield indented non-object", ->
1800+
assertErrorFormat '''
1801+
->
1802+
yield
1803+
1
1804+
''', '''
1805+
[stdin]:3:5: error: unexpected number
1806+
1
1807+
^
1808+
'''
1809+
1810+
test "#3199: error message for yield indented comprehension", ->
1811+
assertErrorFormat '''
1812+
->
1813+
yield
1814+
x for x in [1, 2, 3]
1815+
''', '''
1816+
[stdin]:3:5: error: unexpected identifier
1817+
x for x in [1, 2, 3]
1818+
^
1819+
'''
1820+
1821+
test "#3199: error message for await indented non-object", ->
1822+
assertErrorFormat '''
1823+
->
1824+
await
1825+
1
1826+
''', '''
1827+
[stdin]:3:5: error: unexpected number
1828+
1
1829+
^
1830+
'''
1831+
1832+
test "#3199: error message for await indented comprehension", ->
1833+
assertErrorFormat '''
1834+
->
1835+
await
1836+
x for x in [1, 2, 3]
1837+
''', '''
1838+
[stdin]:3:5: error: unexpected identifier
1839+
x for x in [1, 2, 3]
1840+
^
1841+
'''
1842+
17991843
test "#3098: suppressed newline should be unsuppressed by semicolon", ->
18001844
assertErrorFormat '''
18011845
a = ; 5

test/formatting.coffee

+16
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,22 @@ test "#3199: throw multiline implicit object", ->
417417
msg: 'b'
418418
eq undefined, y
419419

420+
y = do ->
421+
yield
422+
type: 'a'
423+
msg: 'b'
424+
425+
if no then yield
426+
type: 'c'
427+
msg: 'd'
428+
429+
1
430+
{value, done} = y.next()
431+
ok value.type is 'a' and done is no
432+
433+
{value, done} = y.next()
434+
ok value is 1 and done is yes
435+
420436
test "#4576: multiple row function chaining", ->
421437
->
422438
eq @a, 3

0 commit comments

Comments
 (0)