Fixing first part of #614 -- improperly cached existential operator, when first operand is a function call.

This commit is contained in:
Jeremy Ashkenas
2010-08-14 16:24:05 -04:00
parent 1d6eca76f8
commit c90a75ebc5
3 changed files with 22 additions and 18 deletions

View File

@@ -1305,17 +1305,16 @@
o.scope.find(first);
}
if (this.operator === '?=') {
return ("" + (first) + " = " + (ExistenceNode.compileTest(o, literal(firstVar))) + " ? " + (firstVar) + " : " + (second));
return ("" + (first) + " = " + (ExistenceNode.compileTest(o, literal(firstVar))[0]) + " ? " + (firstVar) + " : " + (second));
}
return "" + (first) + " = " + (firstVar) + " " + (this.operator.substr(0, 2)) + " " + (second);
};
OpNode.prototype.compileExistence = function(o) {
var _b, first, second, test;
_b = [this.first.compile(o), this.second.compile(o)];
first = _b[0];
second = _b[1];
test = ExistenceNode.compileTest(o, this.first);
return "" + (test) + " ? " + (first) + " : " + (second);
var _b, ref, test;
_b = ExistenceNode.compileTest(o, this.first);
test = _b[0];
ref = _b[1];
return "" + (test) + " ? " + (ref) + " : " + (this.second.compile(o));
};
OpNode.prototype.compileUnary = function(o) {
var parts, space;
@@ -1439,14 +1438,16 @@
ExistenceNode.prototype["class"] = 'ExistenceNode';
ExistenceNode.prototype.children = ['expression'];
ExistenceNode.prototype.compileNode = function(o) {
return ExistenceNode.compileTest(o, this.expression);
return ExistenceNode.compileTest(o, this.expression)[0];
};
ExistenceNode.compileTest = function(o, variable) {
var _b, first, second;
_b = variable.compileReference(o);
_b = variable.compileReference(o, {
precompile: true
});
first = _b[0];
second = _b[1];
return "(typeof " + (first.compile(o)) + " !== \"undefined\" && " + (second.compile(o)) + " !== null)";
return [("(typeof " + (first) + " !== \"undefined\" && " + (second) + " !== null)"), second];
};
return ExistenceNode;
}).call(this);