1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Issue #2211 -- splats in destructured parameters

This commit is contained in:
Gerald Lewis 2012-03-23 13:20:15 -04:00
parent ddd6e9a48b
commit c5737764b5
3 changed files with 12 additions and 0 deletions

View file

@ -1740,6 +1740,8 @@
obj = _ref2[_i];
if (obj instanceof Assign) {
names.push(obj.variable.base.value);
} else if (obj instanceof Splat) {
names.push(obj.name.unwrap().value);
} else if (obj.isArray() || obj.isObject()) {
names.push.apply(names, this.names(obj.base));
} else if (obj["this"]) {

View file

@ -1278,6 +1278,9 @@ exports.Param = class Param extends Base
# * assignments within destructured parameters `{foo:bar}`
if obj instanceof Assign
names.push obj.variable.base.value
# * splats within destructured parameters `[xs...]`
else if obj instanceof Splat
names.push obj.name.unwrap().value
# * destructured parameters within destructured parameters `[{a}]`
else if obj.isArray() or obj.isObject()
names.push @names(obj.base)...

View file

@ -343,3 +343,10 @@ test "#1838: Regression with variable assignment", ->
'dave'
eq name, 'dave'
test '#2211: splats in destructured parameters', ->
doesNotThrow -> CoffeeScript.compile '([a...]) ->'
doesNotThrow -> CoffeeScript.compile '([a...],b) ->'
doesNotThrow -> CoffeeScript.compile '([a...],[b...]) ->'
throws -> CoffeeScript.compile '([a...,[a...]]) ->'
doesNotThrow -> CoffeeScript.compile '([a...,[b...]]) ->'