unnecessarily strict {in,}equality in existence checks

This commit is contained in:
Michael Ficarra 2011-03-29 17:25:09 -04:00
parent 3d3b03e1e4
commit 31ae260282
3 changed files with 7 additions and 7 deletions

View File

@ -12,7 +12,7 @@
options.bare = true;
return Function(CoffeeScript.compile(code, options))();
};
if (typeof window == "undefined" || window === null) {
if (typeof window == "undefined" || window == null) {
return;
}
CoffeeScript.load = function(url, options) {

View File

@ -811,7 +811,7 @@
}
};
Range.prototype.compileArray = function(o) {
var body, clause, i, idt, post, pre, range, result, vars, _i, _ref, _ref2, _results;
var body, cond, i, idt, post, pre, range, result, vars, _i, _ref, _ref2, _results;
if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
range = (function() {
_results = [];
@ -832,8 +832,8 @@
body = this.compileSimple(o);
} else {
vars = ("" + i + " = " + this.from) + (this.to !== this.toVar ? ", " + this.to : '');
clause = "" + this.fromVar + " <= " + this.toVar + " ?";
body = "var " + vars + "; " + clause + " " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + clause + " " + i + "++ : " + i + "--";
cond = "" + this.fromVar + " <= " + this.toVar;
body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--";
}
post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;
return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this, arguments)";
@ -1805,7 +1805,7 @@
Existence.prototype.compileNode = function(o) {
var code, sym;
code = this.expression.compile(o, LEVEL_OP);
code = IDENTIFIER.test(code) && !o.scope.check(code) ? this.negated ? "typeof " + code + " == \"undefined\" || " + code + " === null" : "typeof " + code + " != \"undefined\" && " + code + " !== null" : (sym = this.negated ? '==' : '!=', "" + code + " " + sym + " null");
code = IDENTIFIER.test(code) && !o.scope.check(code) ? this.negated ? "typeof " + code + " == \"undefined\" || " + code + " == null" : "typeof " + code + " != \"undefined\" && " + code + " != null" : (sym = this.negated ? '==' : '!=', "" + code + " " + sym + " null");
if (o.level <= LEVEL_COND) {
return code;
} else {

View File

@ -1419,9 +1419,9 @@ exports.Existence = class Existence extends Base
code = @expression.compile o, LEVEL_OP
code = if IDENTIFIER.test(code) and not o.scope.check code
if @negated
"typeof #{code} == \"undefined\" || #{code} === null"
"typeof #{code} == \"undefined\" || #{code} == null"
else
"typeof #{code} != \"undefined\" && #{code} !== null"
"typeof #{code} != \"undefined\" && #{code} != null"
else
sym = if @negated then '==' else '!='
"#{code} #{sym} null"