mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
improve variable declaration
This commit is contained in:
@@ -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 we’re 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];
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user