Skip to content

Commit

Permalink
Merge pull request #3324 from xixixao/issue1871
Browse files Browse the repository at this point in the history
Fixes #1871, close implicit objects in implicit returns
  • Loading branch information
michaelficarra committed Jan 23, 2014
2 parents b00962d + 8b976ac commit 5f31a3d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/coffee-script/lexer.js

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

2 changes: 1 addition & 1 deletion lib/coffee-script/rewriter.js

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

3 changes: 2 additions & 1 deletion src/rewriter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ class exports.Rewriter
endImplicitCall()
# Close implicit objects such as:
# return a: 1, b: 2 unless true
else if inImplicitObject() and sameLine and not startsLine
else if inImplicitObject() and sameLine and
tag isnt 'TERMINATOR' and prevTag isnt ':'
endImplicitObject()
# Close implicit objects when at end of line, line didn't end with a comma
# and the implicit object didn't start the line or the next line doesn't look like
Expand Down
17 changes: 17 additions & 0 deletions test/objects.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,23 @@ test "#1871: Special case for IMPLICIT_END in the middle of an implicit object",

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

test "#1871: implicit object closed by IMPLICIT_END in implicit returns", ->
ob = do ->
a: 1 if no
eq ob, undefined

# instead these return an object
func = ->
key:
i for i in [1, 2, 3]

eq func().key.join(' '), '1 2 3'

func = ->
key: (i for i in [1, 2, 3])

eq func().key.join(' '), '1 2 3'

test "#1961, #1974, regression with compound assigning to an implicit object", ->

obj = null
Expand Down

0 comments on commit 5f31a3d

Please sign in to comment.