Skip to content

Commit 5f31a3d

Browse files
Merge pull request #3324 from xixixao/issue1871
Fixes #1871, close implicit objects in implicit returns
2 parents b00962d + 8b976ac commit 5f31a3d

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

lib/coffee-script/lexer.js

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

lib/coffee-script/rewriter.js

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

src/rewriter.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ class exports.Rewriter
302302
endImplicitCall()
303303
# Close implicit objects such as:
304304
# return a: 1, b: 2 unless true
305-
else if inImplicitObject() and sameLine and not startsLine
305+
else if inImplicitObject() and sameLine and
306+
tag isnt 'TERMINATOR' and prevTag isnt ':'
306307
endImplicitObject()
307308
# Close implicit objects when at end of line, line didn't end with a comma
308309
# and the implicit object didn't start the line or the next line doesn't look like

test/objects.coffee

+17
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,23 @@ test "#1871: Special case for IMPLICIT_END in the middle of an implicit object",
387387

388388
eq result.two.join(' '), '2 2 2'
389389

390+
test "#1871: implicit object closed by IMPLICIT_END in implicit returns", ->
391+
ob = do ->
392+
a: 1 if no
393+
eq ob, undefined
394+
395+
# instead these return an object
396+
func = ->
397+
key:
398+
i for i in [1, 2, 3]
399+
400+
eq func().key.join(' '), '1 2 3'
401+
402+
func = ->
403+
key: (i for i in [1, 2, 3])
404+
405+
eq func().key.join(' '), '1 2 3'
406+
390407
test "#1961, #1974, regression with compound assigning to an implicit object", ->
391408

392409
obj = null

0 commit comments

Comments
 (0)