Skip to content

Commit d3f06e3

Browse files
authored
Fixes #5410 (#5413)
1 parent feaea21 commit d3f06e3

File tree

10 files changed

+27
-13
lines changed

10 files changed

+27
-13
lines changed

docs/v2/annotated-source/nodes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9719,7 +9719,7 @@ <h3 id="for">For</h3>
97199719
{index: ivar, name, @step, shouldCache: shouldCacheOrIsAssignable}
97209720
<span class="hljs-keyword">else</span>
97219721
svar = @source.compile o, LEVEL_LIST
9722-
<span class="hljs-keyword">if</span> (name <span class="hljs-keyword">or</span> @own) <span class="hljs-keyword">and</span> @source.unwrap() <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> IdentifierLiteral
9722+
<span class="hljs-keyword">if</span> (name <span class="hljs-keyword">or</span> @own) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> @from <span class="hljs-keyword">and</span> @source.unwrap() <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> IdentifierLiteral
97239723
defPart += <span class="hljs-string">&quot;<span class="hljs-subst">#{@tab}</span><span class="hljs-subst">#{ref = scope.freeVariable <span class="hljs-string">&#x27;ref&#x27;</span>}</span> = <span class="hljs-subst">#{svar}</span>;\n&quot;</span>
97249724
svar = ref
97259725
<span class="hljs-keyword">if</span> name <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> @pattern <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> @from

docs/v2/browser-compiler-legacy/coffeescript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/v2/browser-compiler-modern/coffeescript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/v2/index.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,10 +3469,9 @@ <h2>Generator Functions</h2>
34693469
};
34703470

34713471
getFibonacciNumbers = function(length) {
3472-
var n, ref, results;
3472+
var n, results;
34733473
results = [1];
3474-
ref = fibonacci();
3475-
for (n of ref) {
3474+
for (n of fibonacci()) {
34763475
results.push(n);
34773476
if (results.length === length) {
34783477
break;
@@ -3493,10 +3492,9 @@ <h2>Generator Functions</h2>
34933492
};
34943493

34953494
<span class="cm-variable">getFibonacciNumbers</span> <span class="cm-operator">=</span> <span class="cm-keyword">function</span>(<span class="cm-def">length</span>) {
3496-
<span class="cm-keyword">var</span> <span class="cm-def">n</span>, <span class="cm-def">ref</span>, <span class="cm-def">results</span>;
3495+
<span class="cm-keyword">var</span> <span class="cm-def">n</span>, <span class="cm-def">results</span>;
34973496
<span class="cm-variable-2">results</span> <span class="cm-operator">=</span> [<span class="cm-number">1</span>];
3498-
<span class="cm-variable-2">ref</span> <span class="cm-operator">=</span> <span class="cm-variable">fibonacci</span>();
3499-
<span class="cm-keyword">for</span> (<span class="cm-variable-2">n</span> <span class="cm-keyword">of</span> <span class="cm-variable-2">ref</span>) {
3497+
<span class="cm-keyword">for</span> (<span class="cm-variable-2">n</span> <span class="cm-keyword">of</span> <span class="cm-variable">fibonacci</span>()) {
35003498
<span class="cm-variable-2">results</span>.<span class="cm-property">push</span>(<span class="cm-variable-2">n</span>);
35013499
<span class="cm-keyword">if</span> (<span class="cm-variable-2">results</span>.<span class="cm-property">length</span> <span class="cm-operator">===</span> <span class="cm-variable-2">length</span>) {
35023500
<span class="cm-keyword">break</span>;

docs/v2/test.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19736,6 +19736,14 @@ <h1>CoffeeScript Test Suite</h1>
1973619736
throw new Error "DOOM was called with a null element" unless elm? for elm in elms
1973719737
"""
1973819738

19739+
test "#5410: for from loops shouldn't make excess refs", ->
19740+
js = CoffeeScript.compile """
19741+
for x from fn()
19742+
alert x
19743+
"""
19744+
19745+
ok !js.match /ref/
19746+
1973919747
</script>
1974019748
<script type="text/x-coffeescript" class="test" id="control_flow">
1974119749
# Control Flow

lib/coffeescript-browser-compiler-legacy/coffeescript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript-browser-compiler-modern/coffeescript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/nodes.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5418,7 +5418,7 @@ exports.For = class For extends While
54185418
{index: ivar, name, @step, shouldCache: shouldCacheOrIsAssignable}
54195419
else
54205420
svar = @source.compile o, LEVEL_LIST
5421-
if (name or @own) and @source.unwrap() not instanceof IdentifierLiteral
5421+
if (name or @own) and not @from and @source.unwrap() not instanceof IdentifierLiteral
54225422
defPart += "#{@tab}#{ref = scope.freeVariable 'ref'} = #{svar};\n"
54235423
svar = ref
54245424
if name and not @pattern and not @from

test/comprehensions.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,3 +618,11 @@ test "#5309: comprehension as postfix condition", ->
618618
doesNotThrowCompileError """
619619
throw new Error "DOOM was called with a null element" unless elm? for elm in elms
620620
"""
621+
622+
test "#5410: for from loops shouldn't make excess refs", ->
623+
js = CoffeeScript.compile """
624+
for x from fn()
625+
alert x
626+
"""
627+
628+
ok !js.match /ref/

0 commit comments

Comments
 (0)