mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 03:21:20 -05:00
Fixing destructor in magicked for. Also making destructors in range loops syntax errors.
This commit is contained in:
25
lib/nodes.js
25
lib/nodes.js
@@ -1624,7 +1624,11 @@
|
||||
if (this.index instanceof Value) {
|
||||
throw SyntaxError('index cannot be a pattern matching expression');
|
||||
}
|
||||
this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
|
||||
this.pattern = this.name instanceof Value;
|
||||
if (this.range && this.pattern) {
|
||||
throw SyntaxError('cannot pattern match a range loop');
|
||||
}
|
||||
this.returns = false;
|
||||
return this;
|
||||
};
|
||||
@@ -1648,17 +1652,16 @@
|
||||
return '';
|
||||
};
|
||||
For.prototype.compileNode = function(o) {
|
||||
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lastLine, lvar, name, namePart, nvar, range, ref, resultPart, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, unstepPart, varPart, vars;
|
||||
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lastLine, lvar, name, namePart, nvar, ref, resultPart, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, unstepPart, varPart, vars;
|
||||
topLevel = del(o, 'top') && !this.returns;
|
||||
range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
|
||||
source = range ? this.source.base : this.source;
|
||||
source = this.range ? this.source.base : this.source;
|
||||
codeInBody = !this.body.containsPureStatement() && this.body.contains(function(node) {
|
||||
return node instanceof Code;
|
||||
});
|
||||
scope = o.scope;
|
||||
name = this.name && this.name.compile(o);
|
||||
index = this.index && this.index.compile(o);
|
||||
if (name && !this.pattern && (range || !codeInBody)) {
|
||||
if (name && !this.pattern && (this.range || !codeInBody)) {
|
||||
scope.find(name, {
|
||||
immediate: true
|
||||
});
|
||||
@@ -1671,11 +1674,11 @@
|
||||
if (!topLevel) {
|
||||
rvar = scope.freeVariable('result');
|
||||
}
|
||||
ivar = range ? name : index;
|
||||
ivar = this.range ? name : index;
|
||||
if (!ivar || codeInBody) {
|
||||
ivar = scope.freeVariable('i');
|
||||
}
|
||||
if (name && !range && codeInBody) {
|
||||
if (name && !this.range && codeInBody) {
|
||||
nvar = scope.freeVariable('i');
|
||||
}
|
||||
varPart = '';
|
||||
@@ -1683,7 +1686,7 @@
|
||||
unstepPart = '';
|
||||
body = Expressions.wrap([this.body]);
|
||||
idt1 = this.idt(1);
|
||||
if (range) {
|
||||
if (this.range) {
|
||||
forPart = source.compile(merge(o, {
|
||||
index: ivar,
|
||||
step: this.step
|
||||
@@ -1717,7 +1720,7 @@
|
||||
body = Expressions.wrap([new If(this.guard, body)]);
|
||||
}
|
||||
if (codeInBody) {
|
||||
if (range) {
|
||||
if (this.range) {
|
||||
body.unshift(new Literal("var " + name + " = " + ivar));
|
||||
}
|
||||
if (namePart) {
|
||||
@@ -1737,10 +1740,10 @@
|
||||
o.indent = this.idt(1);
|
||||
body = Expressions.wrap([new Literal(body.compile(o))]);
|
||||
if (index) {
|
||||
body.push(new Assign(new Literal(index), new Literal(ivar)));
|
||||
body.push(new Assign(this.index, new Literal(ivar)));
|
||||
}
|
||||
if (name) {
|
||||
body.push(new Assign(new Literal(name), new Literal(nvar || ivar)));
|
||||
body.push(new Assign(this.name, new Literal(nvar || ivar)));
|
||||
}
|
||||
} else {
|
||||
if (namePart) {
|
||||
@@ -1761,7 +1764,7 @@
|
||||
indent: idt1,
|
||||
top: true
|
||||
}));
|
||||
vars = range ? name : "" + name + ", " + ivar;
|
||||
vars = this.range ? name : "" + name + ", " + ivar;
|
||||
return "" + resultPart + (this.tab) + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + (this.tab) + "}" + unstepPart + returnResult;
|
||||
};
|
||||
return For;
|
||||
|
||||
Reference in New Issue
Block a user