mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
fixed a regression where destructuring for miscompiles
This commit is contained in:
25
lib/nodes.js
25
lib/nodes.js
@@ -1592,7 +1592,7 @@
|
||||
return '';
|
||||
};
|
||||
ForNode.prototype.compileNode = function(o) {
|
||||
var body, codeInBody, forPart, guardPart, index, ivar, lvar, name, namePart, range, ref, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
|
||||
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lvar, name, namePart, range, ref, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
|
||||
topLevel = del(o, 'top') && !this.returns;
|
||||
range = this.source instanceof ValueNode && this.source.base instanceof RangeNode && !this.source.properties.length;
|
||||
source = range ? this.source.base : this.source;
|
||||
@@ -1622,6 +1622,7 @@
|
||||
varPart = '';
|
||||
guardPart = '';
|
||||
body = Expressions.wrap([this.body]);
|
||||
idt1 = this.idt(1);
|
||||
if (range) {
|
||||
sourcePart = source.compileVariables(o);
|
||||
forPart = source.compile(merge(o, {
|
||||
@@ -1639,17 +1640,9 @@
|
||||
sourcePart = ("" + (ref) + " = " + (svar) + ";");
|
||||
svar = ref;
|
||||
}
|
||||
if (this.pattern) {
|
||||
namePart = new AssignNode(this.name, literal("" + (svar) + "[" + (ivar) + "]")).compile(merge(o, {
|
||||
indent: this.idt(1),
|
||||
top: true,
|
||||
keepLevel: true
|
||||
})) + '\n';
|
||||
} else {
|
||||
if (name) {
|
||||
namePart = ("" + (name) + " = " + (svar) + "[" + (ivar) + "]");
|
||||
}
|
||||
}
|
||||
namePart = this.pattern ? new AssignNode(this.name, literal("" + (svar) + "[" + (ivar) + "]")).compile(merge(o, {
|
||||
top: true
|
||||
})) : (name ? ("" + (name) + " = " + (svar) + "[" + (ivar) + "]") : undefined);
|
||||
if (!(this.object)) {
|
||||
lvar = scope.freeVariable('len');
|
||||
stepPart = this.step ? ("" + (ivar) + " += " + (this.step.compile(o))) : ("" + (ivar) + "++");
|
||||
@@ -1677,16 +1670,18 @@
|
||||
}
|
||||
body = ClosureNode.wrap(body, true);
|
||||
} else {
|
||||
varPart = (namePart || '') && (this.pattern ? namePart : ("" + (this.idt(1)) + (namePart) + ";\n"));
|
||||
if (namePart) {
|
||||
varPart = ("" + (idt1) + (namePart) + ";\n");
|
||||
}
|
||||
}
|
||||
if (this.object) {
|
||||
forPart = ("" + (ivar) + " in " + (svar));
|
||||
if (!(this.raw)) {
|
||||
guardPart = ("\n" + (this.idt(1)) + "if (!" + (utility('hasProp')) + ".call(" + (svar) + ", " + (ivar) + ")) continue;");
|
||||
guardPart = ("\n" + (idt1) + "if (!" + (utility('hasProp')) + ".call(" + (svar) + ", " + (ivar) + ")) continue;");
|
||||
}
|
||||
}
|
||||
body = body.compile(merge(o, {
|
||||
indent: this.idt(1),
|
||||
indent: idt1,
|
||||
top: true
|
||||
}));
|
||||
vars = range ? name : ("" + (name) + ", " + (ivar));
|
||||
|
||||
Reference in New Issue
Block a user