mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
made ForNode avoid needless cachings
This commit is contained in:
63
lib/nodes.js
63
lib/nodes.js
@@ -48,7 +48,7 @@
|
||||
return ClosureNode.wrap(this).compile(o);
|
||||
};
|
||||
BaseNode.prototype.compileReference = function(o, options) {
|
||||
var _len, _ref2, compiled, i, node, pair, reference;
|
||||
var _len, compiled, i, node, pair, reference;
|
||||
pair = (function() {
|
||||
if (!(this.isComplex())) {
|
||||
return [this, this];
|
||||
@@ -59,9 +59,8 @@
|
||||
}
|
||||
}).call(this);
|
||||
if (((options != null) ? options.precompile : null)) {
|
||||
_ref2 = pair;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
node = _ref2[i];
|
||||
for (i = 0, _len = pair.length; i < _len; i++) {
|
||||
node = pair[i];
|
||||
(pair[i] = node.compile(o));
|
||||
}
|
||||
}
|
||||
@@ -370,7 +369,7 @@
|
||||
return !o.top || this.properties.length ? ValueNode.__super__.compile.call(this, o) : this.base.compile(o);
|
||||
};
|
||||
ValueNode.prototype.compileNode = function(o) {
|
||||
var _i, _len, _ref2, code, ex, prop, props;
|
||||
var _i, _len, code, ex, prop, props;
|
||||
if (ex = this.unfoldSoak(o)) {
|
||||
return ex.compile(o);
|
||||
}
|
||||
@@ -383,9 +382,8 @@
|
||||
if (props[0] instanceof AccessorNode && this.isNumber() || o.top && this.base instanceof ObjectNode) {
|
||||
code = ("(" + (code) + ")");
|
||||
}
|
||||
_ref2 = props;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
prop = _ref2[_i];
|
||||
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
||||
prop = props[_i];
|
||||
(code += prop.compile(o));
|
||||
}
|
||||
return code;
|
||||
@@ -991,7 +989,7 @@
|
||||
return top || this.parenthetical ? val : ("(" + (val) + ")");
|
||||
};
|
||||
AssignNode.prototype.compilePatternMatch = function(o) {
|
||||
var _len, _ref2, _ref3, accessClass, assigns, code, i, idx, isObject, obj, objects, oindex, olength, otop, splat, top, val, valVar, value;
|
||||
var _len, _ref2, accessClass, assigns, code, i, idx, isObject, obj, objects, oindex, olength, otop, splat, top, val, valVar, value;
|
||||
if ((value = this.value).isStatement(o)) {
|
||||
value = ClosureNode.wrap(value);
|
||||
}
|
||||
@@ -1019,13 +1017,12 @@
|
||||
valVar = o.scope.freeVariable('ref');
|
||||
assigns = [("" + (valVar) + " = " + (value.compile(o)))];
|
||||
splat = false;
|
||||
_ref2 = objects;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
obj = _ref2[i];
|
||||
for (i = 0, _len = objects.length; i < _len; i++) {
|
||||
obj = objects[i];
|
||||
idx = i;
|
||||
if (isObject) {
|
||||
if (obj instanceof AssignNode) {
|
||||
_ref3 = [obj.value, obj.variable.base], obj = _ref3[0], idx = _ref3[1];
|
||||
_ref2 = [obj.value, obj.variable.base], obj = _ref2[0], idx = _ref2[1];
|
||||
} else {
|
||||
idx = obj;
|
||||
}
|
||||
@@ -1119,9 +1116,9 @@
|
||||
}
|
||||
}
|
||||
params = (function() {
|
||||
_result = []; _ref2 = params;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
param = _ref2[_i];
|
||||
_result = [];
|
||||
for (_i = 0, _len = params.length; _i < _len; _i++) {
|
||||
param = params[_i];
|
||||
_result.push(param.compile(o));
|
||||
}
|
||||
return _result;
|
||||
@@ -1129,9 +1126,8 @@
|
||||
if (!(empty)) {
|
||||
this.body.makeReturn();
|
||||
}
|
||||
_ref2 = params;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
param = _ref2[_i];
|
||||
for (_i = 0, _len = params.length; _i < _len; _i++) {
|
||||
param = params[_i];
|
||||
(o.scope.parameter(param));
|
||||
}
|
||||
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
|
||||
@@ -1221,12 +1217,11 @@
|
||||
return "" + (utility('slice')) + ".call(" + (name) + ", " + (index) + (trail) + ")";
|
||||
};
|
||||
SplatNode.compileSplattedArray = function(list, o) {
|
||||
var _len, _ref2, arg, args, code, end, i, prev;
|
||||
var _len, arg, args, code, end, i, prev;
|
||||
args = [];
|
||||
end = -1;
|
||||
_ref2 = list;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
arg = _ref2[i];
|
||||
for (i = 0, _len = list.length; i < _len; i++) {
|
||||
arg = list[i];
|
||||
code = arg.compile(o);
|
||||
prev = args[end];
|
||||
if (!(arg instanceof SplatNode)) {
|
||||
@@ -1619,7 +1614,7 @@
|
||||
return '';
|
||||
};
|
||||
ForNode.prototype.compileNode = function(o) {
|
||||
var body, codeInBody, forPart, guardPart, index, ivar, lvar, name, namePart, range, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
|
||||
var body, codeInBody, forPart, guardPart, 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;
|
||||
@@ -1656,8 +1651,16 @@
|
||||
step: this.step
|
||||
}));
|
||||
} else {
|
||||
svar = scope.freeVariable('ref');
|
||||
sourcePart = ("" + (svar) + " = " + (this.source.compile(o)) + ";");
|
||||
svar = this.source.compile(o);
|
||||
if (IDENTIFIER.test(svar) && scope.check(svar, {
|
||||
immediate: true
|
||||
})) {
|
||||
sourcePart = '';
|
||||
} else {
|
||||
ref = scope.freeVariable('ref');
|
||||
sourcePart = ("" + (ref) + " = " + (svar) + ";");
|
||||
svar = ref;
|
||||
}
|
||||
if (this.pattern) {
|
||||
namePart = new AssignNode(this.name, literal("" + (svar) + "[" + (ivar) + "]")).compile(merge(o, {
|
||||
indent: this.idt(1),
|
||||
@@ -1812,15 +1815,15 @@
|
||||
return this.statement || (this.statement = !!((o && o.top) || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o))));
|
||||
};
|
||||
IfNode.prototype.compileCondition = function(o) {
|
||||
var _i, _len, _ref2, _result, cond, conditions;
|
||||
var _i, _len, _result, cond, conditions;
|
||||
conditions = flatten([this.condition]);
|
||||
if (conditions.length === 1) {
|
||||
conditions[0].parenthetical = true;
|
||||
}
|
||||
return (function() {
|
||||
_result = []; _ref2 = conditions;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
cond = _ref2[_i];
|
||||
_result = [];
|
||||
for (_i = 0, _len = conditions.length; _i < _len; _i++) {
|
||||
cond = conditions[_i];
|
||||
_result.push(cond.compile(o));
|
||||
}
|
||||
return _result;
|
||||
|
||||
Reference in New Issue
Block a user