diff --git a/lib/coffee-script/rewriter.js b/lib/coffee-script/rewriter.js index 2ecc3ad5..867c5f4b 100644 --- a/lib/coffee-script/rewriter.js +++ b/lib/coffee-script/rewriter.js @@ -177,7 +177,9 @@ return this.scanTokens(function(token, i, tokens) { var callObject, current, next, prev, tag, _ref, _ref2, _ref3; tag = token[0]; - if (tag === 'CLASS' || tag === 'IF' || tag === 'FOR') noCall = true; + if (tag === 'CLASS' || tag === 'IF' || tag === 'FOR' || tag === 'WHILE') { + noCall = true; + } _ref = tokens.slice(i - 1, (i + 1) + 1 || 9e9), prev = _ref[0], current = _ref[1], next = _ref[2]; callObject = !noCall && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0); seenSingle = false; diff --git a/src/rewriter.coffee b/src/rewriter.coffee index b9fca27c..ff8add2e 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -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 diff --git a/test/comprehensions.coffee b/test/comprehensions.coffee index 0e8acb9c..4f9a23e4 100644 --- a/test/comprehensions.coffee +++ b/test/comprehensions.coffee @@ -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 diff --git a/test/objects.coffee b/test/objects.coffee index 41f7fc7c..ecafb509 100644 --- a/test/objects.coffee +++ b/test/objects.coffee @@ -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"