From 3ae818860b1d89bd83e7579ee99314eeff95053a Mon Sep 17 00:00:00 2001 From: satyr Date: Tue, 9 Nov 2010 16:27:21 +0900 Subject: [PATCH] fixed a bug where postfix `?` was incorrectly unwrapping its operand --- lib/nodes.js | 2 +- src/nodes.coffee | 2 +- test/test_existence.coffee | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index 34289f60..a2b66491 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1594,7 +1594,7 @@ Existence.prototype.invert = NEGATE; Existence.prototype.compileNode = function(o) { var code, sym; - code = this.expression.compile(o); + 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"); if (o.level <= LEVEL_COND) { return code; diff --git a/src/nodes.coffee b/src/nodes.coffee index 3007b085..ed2cae7a 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1216,7 +1216,7 @@ exports.Existence = class Existence extends Base constructor: (@expression) -> compileNode: (o) -> - code = @expression.compile o + code = @expression.compile o, LEVEL_OP code = if IDENTIFIER.test(code) and not o.scope.check code if @negated "typeof #{code} == \"undefined\" || #{code} === null" diff --git a/test/test_existence.coffee b/test/test_existence.coffee index 097940f7..8c8e2bb7 100644 --- a/test/test_existence.coffee +++ b/test/test_existence.coffee @@ -160,3 +160,6 @@ eq 1, a?.b.c + 1 eq 1, a?.b.c += 1 eq 2, ++a?.b.c eq yes, delete a?.b.c + + +eq (1 or 0)?, true, 'postfix `?` should unwrap correctly'