mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Fix: destructuring assignment with an empty array in object (#5000)
* destructuring assignment with empty array in object * improvements
This commit is contained in:
@@ -2179,7 +2179,7 @@
|
||||
}
|
||||
|
||||
isAssignable() {
|
||||
var j, len1, message, prop, ref1;
|
||||
var j, len1, message, prop, ref1, ref2;
|
||||
ref1 = this.properties;
|
||||
for (j = 0, len1 = ref1.length; j < len1; j++) {
|
||||
prop = ref1[j];
|
||||
@@ -2188,7 +2188,7 @@
|
||||
if (message) {
|
||||
prop.error(message);
|
||||
}
|
||||
if (prop instanceof Assign && prop.context === 'object') {
|
||||
if (prop instanceof Assign && prop.context === 'object' && !(((ref2 = prop.value) != null ? ref2.base : void 0) instanceof Arr)) {
|
||||
prop = prop.value;
|
||||
}
|
||||
if (!prop.isAssignable()) {
|
||||
|
||||
@@ -1477,7 +1477,9 @@ exports.Obj = class Obj extends Base
|
||||
message = isUnassignable prop.unwrapAll().value
|
||||
prop.error message if message
|
||||
|
||||
prop = prop.value if prop instanceof Assign and prop.context is 'object'
|
||||
prop = prop.value if prop instanceof Assign and
|
||||
prop.context is 'object' and
|
||||
prop.value?.base not instanceof Arr
|
||||
return no unless prop.isAssignable()
|
||||
yes
|
||||
|
||||
|
||||
@@ -986,6 +986,23 @@ test "#4878: Compile error when using destructuring with a splat or expansion in
|
||||
|
||||
arrayEq bar(arr), ['a', ['b', 'c', 'd']]
|
||||
|
||||
test "destructuring assignment with an empty array in object", ->
|
||||
obj =
|
||||
a1: [1, 2]
|
||||
b1: 3
|
||||
|
||||
{a1:[], b1} = obj
|
||||
eq 'undefined', typeof a1
|
||||
eq b1, 3
|
||||
|
||||
obj =
|
||||
a2:
|
||||
b2: [1, 2]
|
||||
c2: 3
|
||||
|
||||
{a2: {b2:[]}, c2} = obj
|
||||
eq 'undefined', typeof b2
|
||||
eq c2, 3
|
||||
|
||||
test "#5004: array destructuring with accessors", ->
|
||||
obj =
|
||||
|
||||
Reference in New Issue
Block a user