mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Merge pull request #2299 from geraldalewis/2213-no-method-is-array
Wraps up #2211 -- addresses invocations within destructured params
This commit is contained in:
commit
ed705403ad
3 changed files with 30 additions and 15 deletions
|
@ -1936,15 +1936,19 @@
|
|||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
obj = _ref2[_i];
|
||||
if (obj instanceof Assign) {
|
||||
names.push(obj.value.base.value);
|
||||
names.push(obj.value.unwrap().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"]) {
|
||||
names.push.apply(names, atParam(obj));
|
||||
} else if (obj instanceof Value) {
|
||||
if (obj.isArray() || obj.isObject()) {
|
||||
names.push.apply(names, this.names(obj.base));
|
||||
} else if (obj["this"]) {
|
||||
names.push.apply(names, atParam(obj));
|
||||
} else {
|
||||
names.push(obj.base.value);
|
||||
}
|
||||
} else {
|
||||
names.push(obj.base.value);
|
||||
throw SyntaxError("illegal parameter " + (obj.compile()));
|
||||
}
|
||||
}
|
||||
return names;
|
||||
|
|
|
@ -1297,18 +1297,21 @@ exports.Param = class Param extends Base
|
|||
for obj in name.objects
|
||||
# * assignments within destructured parameters `{foo:bar}`
|
||||
if obj instanceof Assign
|
||||
names.push obj.value.base.value
|
||||
names.push obj.value.unwrap().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)...
|
||||
# * at-params within destructured parameters `{@foo}`
|
||||
else if obj.this
|
||||
names.push atParam(obj)...
|
||||
# * simple destructured parameters {foo}
|
||||
else names.push obj.base.value
|
||||
else if obj instanceof Value
|
||||
# * destructured parameters within destructured parameters `[{a}]`
|
||||
if obj.isArray() or obj.isObject()
|
||||
names.push @names(obj.base)...
|
||||
# * at-params within destructured parameters `{@foo}`
|
||||
else if obj.this
|
||||
names.push atParam(obj)...
|
||||
# * simple destructured parameters {foo}
|
||||
else names.push obj.base.value
|
||||
else
|
||||
throw SyntaxError "illegal parameter #{obj.compile()}"
|
||||
names
|
||||
|
||||
#### Splat
|
||||
|
|
|
@ -357,3 +357,11 @@ test '#2211: splats in destructured parameters', ->
|
|||
doesNotThrow -> CoffeeScript.compile '([a...],[b...]) ->'
|
||||
throws -> CoffeeScript.compile '([a...,[a...]]) ->'
|
||||
doesNotThrow -> CoffeeScript.compile '([a...,[b...]]) ->'
|
||||
|
||||
test '#2213: invocations within destructured parameters', ->
|
||||
throws -> CoffeeScript.compile '([a()])->'
|
||||
throws -> CoffeeScript.compile '([a:b()])->'
|
||||
throws -> CoffeeScript.compile '([a:b.c()])->'
|
||||
throws -> CoffeeScript.compile '({a()})->'
|
||||
throws -> CoffeeScript.compile '({a:b()})->'
|
||||
throws -> CoffeeScript.compile '({a:b.c()})->'
|
||||
|
|
Loading…
Add table
Reference in a new issue