Skip to content

Commit ba09412

Browse files
zdenkoGeoffreyBooth
authored andcommitted
Fix #4882: Range not declaring var for the "i" (#4883)
* fix #4882 * test
1 parent 794f65f commit ba09412

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,11 @@ exports.Range = class Range extends Base
13531353
idx = del o, 'index'
13541354
idxName = del o, 'name'
13551355
namedIndex = idxName and idxName isnt idx
1356-
varPart = "#{idx} = #{@fromC}"
1356+
varPart =
1357+
if known and not namedIndex
1358+
"var #{idx} = #{@fromC}"
1359+
else
1360+
"#{idx} = #{@fromC}"
13571361
varPart += ", #{@toC}" if @toC isnt @toVar
13581362
varPart += ", #{@step}" if @step isnt @stepVar
13591363
[lt, gt] = ["#{idx} <#{@equals}", "#{idx} >#{@equals}"]

test/ranges.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,10 @@ test "#2047: from, to and step as variables", ->
195195
step = 0
196196
r = (x for x in [b..a] by step)
197197
arrayEq r, []
198+
199+
test "#4884: Range not declaring var for the 'i'", ->
200+
'use strict'
201+
[0..21].forEach (idx) ->
202+
idx + 1
203+
204+
eq global.i, undefined

0 commit comments

Comments
 (0)