removing the ability to force an if/else chain to be compiled as a statement. Ternaries will now be used as much as possible.

This commit is contained in:
Jeremy Ashkenas
2010-09-22 00:41:17 -04:00
parent c50cf23b7b
commit c435647589
9 changed files with 16 additions and 54 deletions

View File

@@ -146,9 +146,7 @@
BaseNode.prototype.traverseChildren = function(crossScope, func) {
return this.eachChild(function(child) {
func.apply(this, arguments);
if (child instanceof BaseNode) {
return child.traverseChildren(crossScope, func);
}
return child instanceof BaseNode ? child.traverseChildren(crossScope, func) : null;
});
};
BaseNode.prototype["class"] = 'BaseNode';
@@ -1135,9 +1133,7 @@
return true;
};
CodeNode.prototype.traverseChildren = function(crossScope, func) {
if (crossScope) {
return CodeNode.__super__.traverseChildren.call(this, crossScope, func);
}
return crossScope ? CodeNode.__super__.traverseChildren.call(this, crossScope, func) : null;
};
CodeNode.prototype.toString = function(idt) {
var _i, _len, _ref2, _result, child, children;
@@ -1663,15 +1659,7 @@
if (!(topLevel)) {
rvar = scope.freeVariable('result');
}
ivar = (function() {
if (codeInBody) {
return scope.freeVariable('i');
} else if (range) {
return name;
} else {
return index || scope.freeVariable('i');
}
})();
ivar = codeInBody ? scope.freeVariable('i') : (range ? name : index || scope.freeVariable('i'));
varPart = '';
guardPart = '';
body = Expressions.wrap([this.body]);
@@ -1829,10 +1817,6 @@
IfNode.prototype.elseBodyNode = function() {
return this.elseBody == null ? undefined : this.elseBody.unwrap();
};
IfNode.prototype.forceStatement = function() {
this.tags.statement = true;
return this;
};
IfNode.prototype.addElse = function(elseBody, statement) {
if (this.isChain) {
this.elseBodyNode().addElse(elseBody, statement);
@@ -1843,7 +1827,7 @@
return this;
};
IfNode.prototype.isStatement = function(o) {
return this.statement || (this.statement = (!!((o && o.top) || this.tags.statement || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o)))));
return this.statement || (this.statement = (!!((o && o.top) || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o)))));
};
IfNode.prototype.compileCondition = function(o) {
var _i, _len, _ref2, _result, cond, conditions;