mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Finally got !==
and ===
back to inverting again (instead of wrapping in
`!()`) Also, removed the `@inverted` kludge. It was gross to begin with, but I didn't know the proper way to do it.
This commit is contained in:
parent
dd18703b50
commit
23b4d2fd1d
3 changed files with 37 additions and 10 deletions
|
@ -516,7 +516,7 @@
|
|||
i += expr.length;
|
||||
pi = i + 1;
|
||||
}
|
||||
if (i > pi && pi < str.length) {
|
||||
if ((i > pi && pi < str.length)) {
|
||||
tokens.push(['NEOSTRING', str.slice(pi)]);
|
||||
}
|
||||
if (regex) {
|
||||
|
|
29
lib/nodes.js
29
lib/nodes.js
|
@ -1472,12 +1472,28 @@
|
|||
return (_ref = this.operator) === '<' || _ref === '>' || _ref === '>=' || _ref === '<=' || _ref === '===' || _ref === '!==';
|
||||
};
|
||||
Op.prototype.invert = function() {
|
||||
var fst, op, _ref;
|
||||
var allInvertable, curr, fst, op, _ref;
|
||||
if (this.isChainable() && this.first.isChainable()) {
|
||||
this.inverted = !this.inverted;
|
||||
allInvertable = true;
|
||||
curr = this;
|
||||
while (curr && (curr.operator != null)) {
|
||||
allInvertable && (allInvertable = curr.operator in INVERSIONS);
|
||||
curr = curr.first;
|
||||
}
|
||||
if (!allInvertable) {
|
||||
return new Parens(this).invert();
|
||||
}
|
||||
curr = this;
|
||||
while (curr && (curr.operator != null)) {
|
||||
curr.operator = INVERSIONS[curr.operator];
|
||||
curr = curr.first;
|
||||
}
|
||||
return this;
|
||||
} else if (op = INVERSIONS[this.operator]) {
|
||||
this.operator = op;
|
||||
if (this.first.unwrap() instanceof Op) {
|
||||
this.first.invert();
|
||||
}
|
||||
return this;
|
||||
} else if (this.second) {
|
||||
return new Parens(this).invert();
|
||||
|
@ -1514,12 +1530,11 @@
|
|||
var code, fst, shared, _ref;
|
||||
_ref = this.first.second.cache(o), this.first.second = _ref[0], shared = _ref[1];
|
||||
fst = this.first.compile(o, LEVEL_OP);
|
||||
code = "" + fst + " && " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
|
||||
if (o.level < LEVEL_OP && !this.inverted) {
|
||||
return code;
|
||||
} else {
|
||||
return "" + (this.inverted ? '!' : '') + "(" + code + ")";
|
||||
if (this.first.unwrap() instanceof Op && this.first.isChainable() && fst.charAt(0) === '(') {
|
||||
fst = fst.slice(1, -1);
|
||||
}
|
||||
code = "" + fst + " && " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
|
||||
return "(" + code + ")";
|
||||
};
|
||||
Op.prototype.compileExistence = function(o) {
|
||||
var fst, ref;
|
||||
|
|
|
@ -1174,10 +1174,21 @@ exports.Op = class Op extends Base
|
|||
|
||||
invert: ->
|
||||
if @isChainable() and @first.isChainable()
|
||||
@inverted = !@inverted
|
||||
allInvertable = yes
|
||||
curr = @
|
||||
while curr and curr.operator?
|
||||
allInvertable &&= (curr.operator of INVERSIONS)
|
||||
curr = curr.first
|
||||
return new Parens(this).invert() unless allInvertable
|
||||
curr = @
|
||||
while curr and curr.operator?
|
||||
curr.operator = INVERSIONS[curr.operator]
|
||||
curr = curr.first
|
||||
this
|
||||
else if op = INVERSIONS[@operator]
|
||||
@operator = op
|
||||
if @first.unwrap() instanceof Op
|
||||
@first.invert()
|
||||
this
|
||||
else if @second
|
||||
new Parens(this).invert()
|
||||
|
@ -1207,8 +1218,9 @@ exports.Op = class Op extends Base
|
|||
compileChain: (o) ->
|
||||
[@first.second, shared] = @first.second.cache o
|
||||
fst = @first.compile o, LEVEL_OP
|
||||
fst = fst.slice 1, -1 if @first.unwrap() instanceof Op and @first.isChainable() and fst.charAt(0) is '('
|
||||
code = "#{fst} && #{ shared.compile o } #{@operator} #{ @second.compile o, LEVEL_OP }"
|
||||
if o.level < LEVEL_OP and not @inverted then code else "#{if @inverted then '!' else ''}(#{code})"
|
||||
"(#{code})"
|
||||
|
||||
compileExistence: (o) ->
|
||||
if @first.isComplex()
|
||||
|
|
Loading…
Add table
Reference in a new issue