fixing up compout assignment for ?=, which was using a sligtly different path.

This commit is contained in:
Jeremy Ashkenas
2010-07-31 00:42:57 -04:00
parent 8b953bbde6
commit d4ac11cd4f
3 changed files with 5 additions and 5 deletions

View File

@@ -1293,7 +1293,7 @@
o.scope.find(first); o.scope.find(first);
} }
if (this.operator === '?=') { 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; return "" + first + " = " + firstVar + " " + (this.operator.substr(0, 2)) + " " + second;
}; };

View File

@@ -1112,7 +1112,7 @@ exports.OpNode = class OpNode extends BaseNode
[first, firstVar] = @first.compileReference o, precompile: yes, assignment: yes [first, firstVar] = @first.compileReference o, precompile: yes, assignment: yes
second = @second.compile o second = @second.compile o
o.scope.find(first) if first.match(IDENTIFIER) 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" "#first = #firstVar #{ @operator.substr(0, 2) } #second"
# If this is an existence operator, we delegate to `ExistenceNode.compileTest` # If this is an existence operator, we delegate to `ExistenceNode.compileTest`

View File

@@ -82,15 +82,15 @@ ok two is 'two'
# Compound assignment should be careful about caching variables. # Compound assignment should be careful about caching variables.
list = [0, 0, 5, 10] list = [0, null, 5, 10]
count = 1 count = 1
key = -> key = ->
count += 1 count += 1
list[key()] or= 100 list[key()] or= 100
ok list.join(' ') is '0 0 5 10' ok list.join(' ') is '0 5 10'
count = 0 count = 0
list[key()] or= 100 list[key()] ?= 100
ok list.join(' ') is '0 100 5 10' ok list.join(' ') is '0 100 5 10'