mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Fixes #2621 -- buggy function parameter name detection with complex destructuring in param list.
This commit is contained in:
@@ -1919,7 +1919,7 @@
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
obj = _ref2[_i];
|
||||
if (obj instanceof Assign) {
|
||||
names.push(obj.value.unwrap().value);
|
||||
names.push.apply(names, this.names(obj.value.unwrap()));
|
||||
} else if (obj instanceof Splat) {
|
||||
names.push(obj.name.unwrap().value);
|
||||
} else if (obj instanceof Value) {
|
||||
|
||||
@@ -1128,7 +1128,7 @@ exports.Assign = class Assign extends Base
|
||||
compileConditional: (o) ->
|
||||
[left, right] = @variable.cacheReference o
|
||||
# Disallow conditional assignment of undefined variables.
|
||||
if not left.properties.length and left.base instanceof Literal and
|
||||
if not left.properties.length and left.base instanceof Literal and
|
||||
left.base.value != "this" and not o.scope.check left.base.value
|
||||
throw new Error "the variable \"#{left.base.value}\" can't be assigned with #{@context} because it has not been defined."
|
||||
if "?" in @context then o.isExistentialEquals = true
|
||||
@@ -1289,7 +1289,7 @@ 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.unwrap().value
|
||||
names.push @names(obj.value.unwrap())...
|
||||
# * splats within destructured parameters `[xs...]`
|
||||
else if obj instanceof Splat
|
||||
names.push obj.name.unwrap().value
|
||||
|
||||
@@ -199,10 +199,17 @@ test "#2258: allow whitespace-style parameter lists in function definitions", ->
|
||||
a, b, c
|
||||
) -> c
|
||||
eq func(1, 2, 3), 3
|
||||
|
||||
|
||||
func = (
|
||||
a
|
||||
b
|
||||
c
|
||||
) -> b
|
||||
eq func(1, 2, 3), 2
|
||||
eq func(1, 2, 3), 2
|
||||
|
||||
test "#2621: fancy destructuring in parameter lists", ->
|
||||
func = ({ prop1: { key1 }, prop2: { key2, key3: [a, b, c] } }) ->
|
||||
eq(key2, 'key2')
|
||||
eq(a, 'a')
|
||||
|
||||
func({prop1: {key1: 'key1'}, prop2: {key2: 'key2', key3: ['a', 'b', 'c']}})
|
||||
|
||||
Reference in New Issue
Block a user