From 31ae2602827406684a68dbe345efa8ddfe4b2db6 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Tue, 29 Mar 2011 17:25:09 -0400 Subject: [PATCH] unnecessarily strict {in,}equality in existence checks --- lib/browser.js | 2 +- lib/nodes.js | 8 ++++---- src/nodes.coffee | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/browser.js b/lib/browser.js index 7d78ce38..1b462e7d 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -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) { diff --git a/lib/nodes.js b/lib/nodes.js index 2dbca7ad..2850ce17 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -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 { diff --git a/src/nodes.coffee b/src/nodes.coffee index e7894b4a..a1196ffe 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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"