improve variable declaration

This commit is contained in:
Zdenko Vujasinovic
2017-08-22 10:48:12 +02:00
parent 2491d3286d
commit 5a709ed4a8
2 changed files with 17 additions and 6 deletions

View File

@@ -3237,7 +3237,7 @@
// Check object destructuring variable for rest elements;
// can be removed once ES proposal hits Stage 4.
compileObjectDestruct(o) {
var fragments, getPropKey, getPropName, j, len1, restElement, restElements, result, setScopeVar, traverseRest, value, valueRef;
var fragments, getPropKey, getPropName, j, len1, restElement, restElements, result, setScopeVar, traverseRest, value, valueRef, valueRefTemp;
// Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Assignment_without_declaration,
// if were destructuring without declaring, the destructuring assignment
// must be wrapped in parentheses: `({a, b} = obj)`. Helper function
@@ -3349,12 +3349,19 @@
return restElements;
};
// Cache the value for reuse with rest elements.
[this.value, valueRef] = this.value.cache(o);
if (this.value.shouldCache()) {
valueRefTemp = new IdentifierLiteral(o.scope.freeVariable('ref', {
reserve: false
}));
} else {
valueRefTemp = this.value.base;
}
// Find all rest elements.
restElements = traverseRest(this.variable.base.properties, valueRef);
restElements = traverseRest(this.variable.base.properties, valueRefTemp);
if (!(restElements && restElements.length > 0)) {
return false;
}
[this.value, valueRef] = this.value.cache(o);
result = new Block([this]);
for (j = 0, len1 = restElements.length; j < len1; j++) {
restElement = restElements[j];

View File

@@ -2255,12 +2255,16 @@ exports.Assign = class Assign extends Base
restElements
# Cache the value for reuse with rest elements.
[@value, valueRef] = @value.cache o
if @value.shouldCache()
valueRefTemp = new IdentifierLiteral o.scope.freeVariable 'ref', reserve: false
else
valueRefTemp = @value.base
# Find all rest elements.
restElements = traverseRest @variable.base.properties, valueRef
return false unless restElements and restElements.length > 0
restElements = traverseRest @variable.base.properties, valueRefTemp
return no unless restElements and restElements.length > 0
[@value, valueRef] = @value.cache o
result = new Block [@]
for restElement in restElements