fixed a bug where postfix `?` was incorrectly unwrapping its operand

This commit is contained in:
satyr 2010-11-09 16:27:21 +09:00
parent 188ad03c17
commit 3ae818860b
3 changed files with 5 additions and 2 deletions

View File

@ -1594,7 +1594,7 @@
Existence.prototype.invert = NEGATE; Existence.prototype.invert = NEGATE;
Existence.prototype.compileNode = function(o) { Existence.prototype.compileNode = function(o) {
var code, sym; 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"); 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) { if (o.level <= LEVEL_COND) {
return code; return code;

View File

@ -1216,7 +1216,7 @@ exports.Existence = class Existence extends Base
constructor: (@expression) -> constructor: (@expression) ->
compileNode: (o) -> compileNode: (o) ->
code = @expression.compile o code = @expression.compile o, LEVEL_OP
code = if IDENTIFIER.test(code) and not o.scope.check code code = if IDENTIFIER.test(code) and not o.scope.check code
if @negated if @negated
"typeof #{code} == \"undefined\" || #{code} === null" "typeof #{code} == \"undefined\" || #{code} === null"

View File

@ -160,3 +160,6 @@ eq 1, a?.b.c + 1
eq 1, a?.b.c += 1 eq 1, a?.b.c += 1
eq 2, ++a?.b.c eq 2, ++a?.b.c
eq yes, delete a?.b.c eq yes, delete a?.b.c
eq (1 or 0)?, true, 'postfix `?` should unwrap correctly'