Fixing compound assignment as a right-hand sub expression of a larger operation. Invalid in JS, valid in Coffee.

This commit is contained in:
Jeremy Ashkenas
2010-08-14 14:43:25 -04:00
parent ca18f1fad6
commit c71f2794eb
6 changed files with 32 additions and 9 deletions

View File

@@ -1076,8 +1076,11 @@ exports.OpNode = class OpNode extends BaseNode
isUnary: ->
not @second
isMutator: ->
ends(@operator, '=') and @operator not in ['===', '!==']
isChainable: ->
indexOf(@CHAINABLE, @operator) >= 0
include(@CHAINABLE, @operator)
toString: (idt) ->
super(idt, @class + ' ' + @operator)
@@ -1088,6 +1091,8 @@ exports.OpNode = class OpNode extends BaseNode
return @compileAssignment(o) if indexOf(@ASSIGNMENT, @operator) >= 0
return @compileUnary(o) if @isUnary()
return @compileExistence(o) if @operator is '?'
@first = new ParentheticalNode(@first) if @first instanceof OpNode and @first.isMutator()
@second = new ParentheticalNode(@second) if @second instanceof OpNode and @second.isMutator()
[@first.compile(o), @operator, @second.compile(o)].join ' '
# Mimic Python's chained comparisons when multiple comparison operators are