mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 09:17:55 -05:00
coco 31ad9f0: nodes: made Op::invert more accurate
This commit is contained in:
13
lib/nodes.js
13
lib/nodes.js
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user