From b608d4a5eab77389f843e87bb8ba389adea1897c Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Tue, 17 Aug 2010 21:46:00 -0400 Subject: [PATCH] Issue #626. Making the isInvertible check a little stricter. --- lib/nodes.js | 9 +++++---- src/nodes.coffee | 12 +++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index a7a405a2..05520eb3 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1285,12 +1285,13 @@ OpNode.prototype.isUnary = function() { return !this.second; }; - OpNode.prototype.isInvertable = function() { + OpNode.prototype.isInvertible = function() { var _b; - return ('===' === (_b = this.operator) || '!==' === _b); + return (('===' === (_b = this.operator) || '!==' === _b)) && !(this.first instanceof OpNode) && !(this.second instanceof OpNode); }; OpNode.prototype.isMutator = function() { - return ends(this.operator, '=') && !this.isInvertable(); + var _b; + return ends(this.operator, '=') && !(('===' === (_b = this.operator) || '!==' === _b)); }; OpNode.prototype.isChainable = function() { return include(this.CHAINABLE, this.operator); @@ -1683,7 +1684,7 @@ this.condition = _b; this.tags || (this.tags = {}); if (this.tags.invert) { - if (this.condition instanceof OpNode && this.condition.isInvertable()) { + if (this.condition instanceof OpNode && this.condition.isInvertible()) { this.condition.invert(); } else { this.condition = new OpNode('!', new ParentheticalNode(this.condition)); diff --git a/src/nodes.coffee b/src/nodes.coffee index 572eaa13..0c32e902 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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