mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
* fix #4882 * test
This commit is contained in:
parent
794f65fbd7
commit
ba094126e2
3 changed files with 13 additions and 2 deletions
|
@ -2043,7 +2043,7 @@
|
|||
idx = del(o, 'index');
|
||||
idxName = del(o, 'name');
|
||||
namedIndex = idxName && idxName !== idx;
|
||||
varPart = `${idx} = ${this.fromC}`;
|
||||
varPart = known && !namedIndex ? `var ${idx} = ${this.fromC}` : `${idx} = ${this.fromC}`;
|
||||
if (this.toC !== this.toVar) {
|
||||
varPart += `, ${this.toC}`;
|
||||
}
|
||||
|
|
|
@ -1353,7 +1353,11 @@ exports.Range = class Range extends Base
|
|||
idx = del o, 'index'
|
||||
idxName = del o, 'name'
|
||||
namedIndex = idxName and idxName isnt idx
|
||||
varPart = "#{idx} = #{@fromC}"
|
||||
varPart =
|
||||
if known and not namedIndex
|
||||
"var #{idx} = #{@fromC}"
|
||||
else
|
||||
"#{idx} = #{@fromC}"
|
||||
varPart += ", #{@toC}" if @toC isnt @toVar
|
||||
varPart += ", #{@step}" if @step isnt @stepVar
|
||||
[lt, gt] = ["#{idx} <#{@equals}", "#{idx} >#{@equals}"]
|
||||
|
|
|
@ -195,3 +195,10 @@ test "#2047: from, to and step as variables", ->
|
|||
step = 0
|
||||
r = (x for x in [b..a] by step)
|
||||
arrayEq r, []
|
||||
|
||||
test "#4884: Range not declaring var for the 'i'", ->
|
||||
'use strict'
|
||||
[0..21].forEach (idx) ->
|
||||
idx + 1
|
||||
|
||||
eq global.i, undefined
|
||||
|
|
Loading…
Reference in a new issue