ensure Value; breaking test for {a={b...}} = c

This commit is contained in:
Julian Rosse 2017-08-21 10:34:33 -04:00
parent 2664c2c108
commit 2149c3561b
3 changed files with 14 additions and 13 deletions

View File

@ -3288,8 +3288,12 @@
var base1, index, j, len1, nestedProperties, nestedSource, nestedSourceDefault, p, prop, restElements, restIndex;
restElements = [];
restIndex = void 0;
if (source.properties == null) {
source = new Value(source);
}
for (index = j = 0, len1 = properties.length; j < len1; index = ++j) {
prop = properties[index];
nestedSourceDefault = nestedSource = nestedProperties = null;
setScopeVar(prop.unwrap());
if (prop instanceof Assign) {
if (typeof (base1 = prop.value).isObject === "function" ? base1.isObject() : void 0) {
@ -3301,14 +3305,10 @@
[prop.value.value, nestedSourceDefault] = prop.value.value.cache(o);
}
if (nestedProperties) {
if (source.properties) {
nestedSource = new Value(source.base, source.properties.concat([new Access(getPropKey(prop))]));
if (nestedSourceDefault) {
nestedSource = new Value(new Op('?', nestedSource, nestedSourceDefault));
}
} else {
nestedSource = source;
}
restElements.push(...traverseRest(nestedProperties, nestedSource));
}
} else if (prop instanceof Splat) {

View File

@ -2216,8 +2216,10 @@ exports.Assign = class Assign extends Base
traverseRest = (properties, source) =>
restElements = []
restIndex = undefined
source = new Value source unless source.properties?
for prop, index in properties
nestedSourceDefault = nestedSource = nestedProperties = null
setScopeVar prop.unwrap()
if prop instanceof Assign
# prop is `k: expr`, we need to check `expr` for nested splats
@ -2229,11 +2231,8 @@ exports.Assign = class Assign extends Base
nestedProperties = prop.value.variable.base.properties
[prop.value.value, nestedSourceDefault] = prop.value.value.cache o
if nestedProperties
if source.properties
nestedSource = new Value source.base, source.properties.concat [new Access getPropKey prop]
nestedSource = new Value new Op '?', nestedSource, nestedSourceDefault if nestedSourceDefault
else
nestedSource = source
restElements.push traverseRest(nestedProperties, nestedSource)...
else if prop instanceof Splat
prop.error "multiple rest elements are disallowed in object destructuring" if restIndex?

View File

@ -305,9 +305,11 @@ test "destructuring assignment with multiple splats in different objects", ->
s: 6
}
}
{p: {m}, r...} = o.props
{p: {m, q..., t = {obj...}}, r...} = o.props
eq m, o.props.p.m
deepEqual r, s: 6
deepEqual q, n: 1
deepEqual t, obj
@props = o.props
{p: {m}, r...} = @props