fix another long ternary in the lib

This commit is contained in:
Mike Blume
2011-08-03 22:27:36 -07:00
parent 396f9b3a12
commit 15fed8d17f
2 changed files with 10 additions and 5 deletions

View File

@@ -1864,7 +1864,12 @@
Existence.prototype.compileNode = function(o) {
var cmp, cnj, code, _ref2;
code = this.expression.compile(o, LEVEL_OP);
code = IDENTIFIER.test(code) && !o.scope.check(code) ? ((_ref2 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref2[0], cnj = _ref2[1], _ref2), "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null") : "" + code + " " + (this.negated ? '==' : '!=') + " null";
if (IDENTIFIER.test(code) && !o.scope.check(code)) {
_ref2 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref2[0], cnj = _ref2[1];
code = "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null";
} else {
code = "" + code + " " + (this.negated ? '==' : '!=') + " null";
}
if (o.level <= LEVEL_COND) {
return code;
} else {

View File

@@ -1451,12 +1451,12 @@ exports.Existence = class Existence extends Base
compileNode: (o) ->
code = @expression.compile o, LEVEL_OP
code = if IDENTIFIER.test(code) and not o.scope.check code
[cmp, cnj] = if @negated then ['===', '||'] else ['!==', '&&']
"typeof #{code} #{cmp} \"undefined\" #{cnj} #{code} #{cmp} null"
if IDENTIFIER.test(code) and not o.scope.check code
[cmp, cnj] = if @negated then ['===', '||'] else ['!==', '&&']
code = "typeof #{code} #{cmp} \"undefined\" #{cnj} #{code} #{cmp} null"
else
# do not use strict equality here; it will break existing code
"#{code} #{if @negated then '==' else '!='} null"
code = "#{code} #{if @negated then '==' else '!='} null"
if o.level <= LEVEL_COND then code else "(#{code})"
#### Parens