made until less parenful as well

This commit is contained in:
satyr
2010-10-11 07:29:38 +09:00
parent 6e6165796c
commit c437f0b14b
2 changed files with 23 additions and 44 deletions

View File

@@ -141,9 +141,12 @@
if (func(child) === false) {
return false;
}
return child instanceof Base && (crossScope || !(child instanceof Code)) ? child.traverseChildren(crossScope, func) : undefined;
return crossScope || !(child instanceof Code) ? child.traverseChildren(crossScope, func) : undefined;
});
};
Base.prototype.invert = function() {
return new Op('!', this);
};
Base.prototype.children = [];
Base.prototype.unwrap = THIS;
Base.prototype.isStatement = NO;
@@ -1271,13 +1274,7 @@
While = (function() {
return function While(condition, opts) {
While.__super__.constructor.call(this);
if (((opts != null) ? opts.invert : undefined)) {
if (condition instanceof Op) {
condition = new Parens(condition);
}
condition = new Op('!', condition);
}
this.condition = condition;
this.condition = ((opts != null) ? opts.invert : undefined) ? condition.invert() : condition;
this.guard = ((opts != null) ? opts.guard : undefined);
return this;
};
@@ -1362,10 +1359,6 @@
Op.prototype.isUnary = function() {
return !this.second;
};
Op.prototype.isInvertible = function() {
var _ref2;
return ('===' === (_ref2 = this.operator) || '!==' === _ref2);
};
Op.prototype.isComplex = function() {
return this.operator !== '!' || this.first.isComplex();
};
@@ -1377,7 +1370,11 @@
return include(this.CHAINABLE, this.operator);
};
Op.prototype.invert = function() {
return (this.operator = this.INVERSIONS[this.operator]);
var _ref2;
if (('===' === (_ref2 = this.operator) || '!==' === _ref2)) {
this.operator = this.INVERSIONS[this.operator];
return this;
} else return this.second ? new Parens(this).invert() : Op.__super__.invert.call(this);
};
Op.prototype.toString = function(idt) {
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
@@ -1780,22 +1777,10 @@
exports.If = (function() {
If = (function() {
return function If(condition, _arg, _arg2) {
var op;
this.tags = _arg2;
this.body = _arg;
this.tags || (this.tags = {});
if (this.tags.invert) {
op = condition instanceof Op;
if (op && condition.isInvertible()) {
condition.invert();
} else {
if (op && !condition.isUnary()) {
condition = new Parens(condition);
}
condition = new Op('!', condition);
}
}
this.condition = condition;
this.condition = this.tags.invert ? condition.invert() : condition;
this.elseBody = null;
this.isChain = false;
return this;