fix assign in nested properties

fix assign in nested properties
This commit is contained in:
Zdenko Vujasinovic
2017-08-21 21:12:31 +02:00
parent 1a6477adec
commit 2491d3286d
2 changed files with 26 additions and 7 deletions

View File

@@ -3142,7 +3142,7 @@
// we've been assigned to, for correct internal references. If the variable
// has not been seen yet within the current scope, declare it.
compileNode(o) {
var answer, compiledName, isValue, j, name, properties, prototype, ref1, ref2, ref3, ref4, ref5, val, varBase;
var answer, compiledName, isValue, j, name, objDestructAnswer, properties, prototype, ref1, ref2, ref3, ref4, ref5, val, varBase;
isValue = this.variable instanceof Value;
if (isValue) {
// When compiling `@variable`, remember if it is part of a function parameter.
@@ -3163,7 +3163,10 @@
return node instanceof Obj && node.hasSplat();
})) {
// Object destructuring. Can be removed once ES proposal hits Stage 4.
return this.compileObjectDestruct(o);
objDestructAnswer = this.compileObjectDestruct(o);
}
if (objDestructAnswer) {
return objDestructAnswer;
}
}
if (this.variable.isSplice()) {
@@ -3297,8 +3300,14 @@
setScopeVar(prop.unwrap());
if (prop instanceof Assign) {
if (typeof (base1 = prop.value).isObject === "function" ? base1.isObject() : void 0) {
// prop is `k: {...}`
nestedProperties = prop.value.base.properties;
if (prop.operatorToken.unwrap().value === ':') {
// prop is `k: {...}`
nestedProperties = prop.value.base.properties;
}
if (prop.operatorToken.unwrap().value === '=') {
// prop is `k = {...} `
continue;
}
} else if (prop.value instanceof Assign && prop.value.variable.isObject()) {
// prop is `k: {...} = default`
nestedProperties = prop.value.variable.base.properties;
@@ -3343,6 +3352,9 @@
[this.value, valueRef] = this.value.cache(o);
// Find all rest elements.
restElements = traverseRest(this.variable.base.properties, valueRef);
if (!(restElements && restElements.length > 0)) {
return false;
}
result = new Block([this]);
for (j = 0, len1 = restElements.length; j < len1; j++) {
restElement = restElements[j];

View File

@@ -2122,8 +2122,9 @@ exports.Assign = class Assign extends Base
@variable.base.lhs = yes
return @compileDestructuring o unless @variable.isAssignable()
# Object destructuring. Can be removed once ES proposal hits Stage 4.
return @compileObjectDestruct(o) if @variable.isObject() and @variable.contains (node) ->
objDestructAnswer = @compileObjectDestruct(o) if @variable.isObject() and @variable.contains (node) ->
node instanceof Obj and node.hasSplat()
return objDestructAnswer if objDestructAnswer
return @compileSplice o if @variable.isSplice()
return @compileConditional o if @context in ['||=', '&&=', '?=']
@@ -2224,8 +2225,12 @@ exports.Assign = class Assign extends Base
if prop instanceof Assign
# prop is `k: expr`, we need to check `expr` for nested splats
if prop.value.isObject?()
# prop is `k: {...}`
nestedProperties = prop.value.base.properties
if prop.operatorToken.unwrap().value is ':'
# prop is `k: {...}`
nestedProperties = prop.value.base.properties
if prop.operatorToken.unwrap().value is '='
# prop is `k = {...} `
continue
else if prop.value instanceof Assign and prop.value.variable.isObject()
# prop is `k: {...} = default`
nestedProperties = prop.value.variable.base.properties
@@ -2254,8 +2259,10 @@ exports.Assign = class Assign extends Base
# Find all rest elements.
restElements = traverseRest @variable.base.properties, valueRef
return false unless restElements and restElements.length > 0
result = new Block [@]
for restElement in restElements
value = new Call new Value(new Literal utility 'objectWithoutKeys', o), [restElement.source, restElement.excludeProps]
result.push new Assign restElement.name, value