coco 31ad9f0: nodes: made Op::invert more accurate

This commit is contained in:
Jeremy Ashkenas
2010-11-14 15:07:43 -05:00
parent a1aaa4495c
commit f31798bbb4
3 changed files with 25 additions and 13 deletions

View File

@@ -1322,6 +1322,7 @@
return While;
}();
exports.Op = Op = function() {
var CONVERSIONS, INVERSIONS;
function Op(op, first, second, flip) {
if (op === 'in') {
return new In(first, second);
@@ -1334,18 +1335,18 @@
first = new Parens(first);
}
}
this.operator = this.CONVERSIONS[op] || op;
this.operator = CONVERSIONS[op] || op;
this.first = first;
this.second = second;
this.flip = !!flip;
}
__extends(Op, Base);
Op.prototype.CONVERSIONS = {
CONVERSIONS = {
'==': '===',
'!=': '!==',
'of': 'in'
};
Op.prototype.INVERSIONS = {
INVERSIONS = {
'!==': '===',
'===': '!==',
'>': '<=',
@@ -1362,12 +1363,14 @@
return (_ref = this.operator) === '<' || _ref === '>' || _ref === '>=' || _ref === '<=' || _ref === '===' || _ref === '!==';
};
Op.prototype.invert = function() {
var op;
if (op = this.INVERSIONS[this.operator]) {
var fst, op, _ref;
if (op = INVERSIONS[this.operator]) {
this.operator = op;
return this;
} else if (this.second) {
return new Parens(this).invert();
} else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref = fst.operator) === '!' || _ref === 'in' || _ref === 'instanceof')) {
return fst;
} else {
return new Op('!', this);
}