diff --git a/lib/nodes.js b/lib/nodes.js index 8b12d940..346ddce5 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1293,7 +1293,7 @@ o.scope.find(first); } if (this.operator === '?=') { - return ("" + first + " = " + (ExistenceNode.compileTest(o, this.first)) + " ? " + firstVar + " : " + second); + return ("" + first + " = " + (ExistenceNode.compileTest(o, literal(firstVar))) + " ? " + firstVar + " : " + second); } return "" + first + " = " + firstVar + " " + (this.operator.substr(0, 2)) + " " + second; }; diff --git a/src/nodes.coffee b/src/nodes.coffee index d702c9cf..04da956a 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1112,7 +1112,7 @@ exports.OpNode = class OpNode extends BaseNode [first, firstVar] = @first.compileReference o, precompile: yes, assignment: yes second = @second.compile o o.scope.find(first) if first.match(IDENTIFIER) - return "#first = #{ ExistenceNode.compileTest(o, @first) } ? #firstVar : #second" if @operator is '?=' + return "#first = #{ ExistenceNode.compileTest(o, literal(firstVar)) } ? #firstVar : #second" if @operator is '?=' "#first = #firstVar #{ @operator.substr(0, 2) } #second" # If this is an existence operator, we delegate to `ExistenceNode.compileTest` diff --git a/test/test_operations.coffee b/test/test_operations.coffee index b99dd0ec..3151f3f2 100644 --- a/test/test_operations.coffee +++ b/test/test_operations.coffee @@ -82,15 +82,15 @@ ok two is 'two' # Compound assignment should be careful about caching variables. -list = [0, 0, 5, 10] +list = [0, null, 5, 10] count = 1 key = -> count += 1 list[key()] or= 100 -ok list.join(' ') is '0 0 5 10' +ok list.join(' ') is '0 5 10' count = 0 -list[key()] or= 100 +list[key()] ?= 100 ok list.join(' ') is '0 100 5 10' \ No newline at end of file