Skip to content

Commit ece9c54

Browse files
committed
Fixes jashkenas#1871, close implicit objects in implicit returns
1 parent b00962d commit ece9c54

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ 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 tag isnt 'TERMINATOR'
306306
endImplicitObject()
307307
# Close implicit objects when at end of line, line didn't end with a comma
308308
# and the implicit object didn't start the line or the next line doesn't look like

test/objects.coffee

+17-6
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+
for i in [1, 2, 3] then i
399+
400+
eq func().key.join(' '), '1 2 3'
401+
402+
func = ->
403+
key: (for i in [1, 2, 3] then i)
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
@@ -405,12 +422,6 @@ test "#1961, #1974, regression with compound assigning to an implicit object", -
405422

406423
eq obj.four, 4
407424

408-
test "#2207: Immediate implicit closes don't close implicit objects", ->
409-
func = ->
410-
key: for i in [1, 2, 3] then i
411-
412-
eq func().key.join(' '), '1 2 3'
413-
414425
test 'inline implicit object literals within multiline implicit object literals', ->
415426
x =
416427
a: aa: 0

0 commit comments

Comments
 (0)