Issue #626. Making the isInvertible check a little stricter.

This commit is contained in:
Jeremy Ashkenas
2010-08-17 21:46:00 -04:00
parent 4d32c47bee
commit b608d4a5ea
2 changed files with 12 additions and 9 deletions

View File

@@ -1083,7 +1083,7 @@ exports.OpNode = class OpNode extends BaseNode
'==': '==='
'!=': '!=='
# The map of invertable operators.
# The map of invertible operators.
INVERSIONS:
'!==': '==='
'===': '!=='
@@ -1113,11 +1113,13 @@ exports.OpNode = class OpNode extends BaseNode
isUnary: ->
not @second
isInvertable: ->
@operator in ['===', '!==']
isInvertible: ->
(@operator in ['===', '!==']) and
not (@first instanceof OpNode) and not (@second instanceof OpNode)
isMutator: ->
ends(@operator, '=') and not @isInvertable()
ends(@operator, '=') and not (@operator in ['===', '!=='])
isChainable: ->
include(@CHAINABLE, @operator)
@@ -1413,7 +1415,7 @@ exports.IfNode = class IfNode extends BaseNode
constructor: (@condition, @body, @tags) ->
@tags or= {}
if @tags.invert
if @condition instanceof OpNode and @condition.isInvertable()
if @condition instanceof OpNode and @condition.isInvertible()
@condition.invert()
else
@condition = new OpNode '!', new ParentheticalNode @condition