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

@@ -1285,12 +1285,13 @@
OpNode.prototype.isUnary = function() { OpNode.prototype.isUnary = function() {
return !this.second; return !this.second;
}; };
OpNode.prototype.isInvertable = function() { OpNode.prototype.isInvertible = function() {
var _b; var _b;
return ('===' === (_b = this.operator) || '!==' === _b); return (('===' === (_b = this.operator) || '!==' === _b)) && !(this.first instanceof OpNode) && !(this.second instanceof OpNode);
}; };
OpNode.prototype.isMutator = function() { OpNode.prototype.isMutator = function() {
return ends(this.operator, '=') && !this.isInvertable(); var _b;
return ends(this.operator, '=') && !(('===' === (_b = this.operator) || '!==' === _b));
}; };
OpNode.prototype.isChainable = function() { OpNode.prototype.isChainable = function() {
return include(this.CHAINABLE, this.operator); return include(this.CHAINABLE, this.operator);
@@ -1683,7 +1684,7 @@
this.condition = _b; this.condition = _b;
this.tags || (this.tags = {}); this.tags || (this.tags = {});
if (this.tags.invert) { if (this.tags.invert) {
if (this.condition instanceof OpNode && this.condition.isInvertable()) { if (this.condition instanceof OpNode && this.condition.isInvertible()) {
this.condition.invert(); this.condition.invert();
} else { } else {
this.condition = new OpNode('!', new ParentheticalNode(this.condition)); this.condition = new OpNode('!', new ParentheticalNode(this.condition));

View File

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