Fix: destructuring assignment with an empty array in object (#5000)

* destructuring assignment with empty array in object

* improvements
This commit is contained in:
zdenko 2018-03-10 16:39:35 +01:00 committed by Geoffrey Booth
parent 4c0363fb7c
commit 1869f3121d
3 changed files with 22 additions and 3 deletions

View File

@ -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()) {

View File

@ -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

View File

@ -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 =