Merge pull request #3791 from lydell/issue-3502
Fix #3502: Define param variables when expansion
This commit is contained in:
commit
669e7fed10
|
@ -1874,11 +1874,9 @@
|
|||
}
|
||||
_ref5 = this.params;
|
||||
for (_k = 0, _len2 = _ref5.length; _k < _len2; _k++) {
|
||||
p = _ref5[_k].name;
|
||||
if (!(param instanceof Expansion)) {
|
||||
if (p.value) {
|
||||
o.scope.add(p.value, 'var', true);
|
||||
}
|
||||
p = _ref5[_k];
|
||||
if (!(p instanceof Expansion) && p.name.value) {
|
||||
o.scope.add(p.name.value, 'var', true);
|
||||
}
|
||||
}
|
||||
splats = new Assign(new Value(new Arr((function() {
|
||||
|
|
|
@ -1360,8 +1360,8 @@ exports.Code = class Code extends Base
|
|||
for param in @params when param not instanceof Expansion
|
||||
o.scope.parameter param.asReference o
|
||||
for param in @params when param.splat or param instanceof Expansion
|
||||
for {name: p} in @params when param not instanceof Expansion
|
||||
if p.value then o.scope.add p.value, 'var', yes
|
||||
for p in @params when p not instanceof Expansion and p.name.value
|
||||
o.scope.add p.name.value, 'var', yes
|
||||
splats = new Assign new Value(new Arr(p.asReference o for p in @params)),
|
||||
new Value new Literal 'arguments'
|
||||
break
|
||||
|
|
|
@ -198,6 +198,20 @@ test "#156: parameter lists with expansion in array destructuring", ->
|
|||
last
|
||||
eq 3, expandArray 1, 2, 3, [1, 2, 3]
|
||||
|
||||
test "#3502: variable definitions and expansion", ->
|
||||
a = b = 0
|
||||
f = (a, ..., b) -> [a, b]
|
||||
arrayEq [1, 5], f 1, 2, 3, 4, 5
|
||||
eq 0, a
|
||||
eq 0, b
|
||||
|
||||
test "variable definitions and splat", ->
|
||||
a = b = 0
|
||||
f = (a, middle..., b) -> [a, middle, b]
|
||||
arrayEq [1, [2, 3, 4], 5], f 1, 2, 3, 4, 5
|
||||
eq 0, a
|
||||
eq 0, b
|
||||
|
||||
test "default values with function calls", ->
|
||||
doesNotThrow -> CoffeeScript.compile "(x = f()) ->"
|
||||
|
||||
|
|
Loading…
Reference in New Issue