Skip to content

Commit

Permalink
merging/improving @rolftimmermans fix/tests for jashkenas#2007
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Feb 14, 2012
1 parent 8248601 commit 28a1101
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/coffee-script/rewriter.js

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

2 changes: 1 addition & 1 deletion src/rewriter.coffee
Expand Up @@ -167,7 +167,7 @@ class exports.Rewriter

@scanTokens (token, i, tokens) ->
tag = token[0]
noCall = yes if tag in ['CLASS', 'IF', 'FOR']
noCall = yes if tag in ['CLASS', 'IF', 'FOR', 'WHILE']
[prev, current, next] = tokens[i - 1 .. i + 1]
callObject = not noCall and tag is 'INDENT' and
next and next.generated and next[0] is '{' and
Expand Down
14 changes: 14 additions & 0 deletions test/comprehensions.coffee
Expand Up @@ -485,3 +485,17 @@ test "#1910: loop index should be mutable within a loop iteration and immutable
++iterations
eq 6, k
eq 5, iterations

test "#2007: Return object literal from comprehension", ->
y = for x in [1, 2]
foo: "foo" + x
eq 2, y.length
eq "foo1", y[0].foo
eq "foo2", y[1].foo

x = 2
y = while x
x: --x
eq 2, y.length
eq 1, y[0].x
eq 0, y[1].x
7 changes: 0 additions & 7 deletions test/objects.coffee
Expand Up @@ -269,10 +269,3 @@ test "#1961, #1974, regression with compound assigning to an implicit object", -
four: 4

eq obj.four, 4

test "#2007: Return object literal from comprehension", ->
y = for x in [1, 2]
foo: "foo"
bar: "bar"

eq y[0].foo, "foo"

0 comments on commit 28a1101

Please sign in to comment.