Skip to content

Fixes #1871, close implicit objects in implicit returns #3324

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 1 commit into from
Jan 23, 2014
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
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", ->

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. Why did this one have to be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a test for the old behavior, so I moved the code to the current test and modified it. The current PR is almost direct opposite of the functionality that this test used to test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not quite. There's a big difference between a: for b in c then b and a: b for b in c.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very good catch!

obj = null
Expand Down