mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 03:21:20 -05:00
nodes: removed some redundancies and unused methods
This commit is contained in:
71
lib/nodes.js
71
lib/nodes.js
@@ -31,19 +31,17 @@
|
||||
return Base;
|
||||
})();
|
||||
Base.prototype.compile = function(o) {
|
||||
var closure, code, top;
|
||||
this.options = o ? merge(o) : {};
|
||||
var top;
|
||||
o = o ? merge(o) : {};
|
||||
top = this.topSensitive() ? o.top : del(o, 'top');
|
||||
this.tab = o.indent;
|
||||
top = this.topSensitive() ? this.options.top : del(this.options, 'top');
|
||||
closure = this.isStatement(o) && !this.isPureStatement() && !top && !this.options.asStatement && !(this instanceof Comment);
|
||||
code = closure ? this.compileClosure(this.options) : this.compileNode(this.options);
|
||||
return code;
|
||||
return top || o.asStatement || this instanceof Comment || this.isPureStatement() || !this.isStatement(o) ? this.compileNode(o) : this.compileClosure(o);
|
||||
};
|
||||
Base.prototype.compileClosure = function(o) {
|
||||
o.sharedScope = o.scope;
|
||||
if (this.containsPureStatement()) {
|
||||
throw SyntaxError('cannot include a pure statement in an expression.');
|
||||
}
|
||||
o.sharedScope = o.scope;
|
||||
return Closure.wrap(this).compile(o);
|
||||
};
|
||||
Base.prototype.compileReference = function(o, options) {
|
||||
@@ -72,9 +70,9 @@
|
||||
Base.prototype.compileLoopReference = function(o, name) {
|
||||
var src, tmp;
|
||||
src = tmp = this.compile(o);
|
||||
if (!(NUMBER.test(src) || (IDENTIFIER.test(src) && o.scope.check(src, {
|
||||
if (!(NUMBER.test(src) || IDENTIFIER.test(src) && o.scope.check(src, {
|
||||
immediate: true
|
||||
})))) {
|
||||
}))) {
|
||||
src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src;
|
||||
}
|
||||
return [src, tmp];
|
||||
@@ -106,9 +104,6 @@
|
||||
return node.isPureStatement();
|
||||
});
|
||||
};
|
||||
Base.prototype.traverse = function(block) {
|
||||
return this.traverseChildren(true, block);
|
||||
};
|
||||
Base.prototype.toString = function(idt, override) {
|
||||
var _i, _len, _ref2, _result, child, children, klass;
|
||||
idt || (idt = '');
|
||||
@@ -127,7 +122,7 @@
|
||||
Base.prototype.eachChild = function(func) {
|
||||
var _i, _j, _len, _len2, _ref2, _ref3, attr, child;
|
||||
if (!this.children) {
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
_ref2 = this.children;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
@@ -137,7 +132,7 @@
|
||||
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
|
||||
child = _ref3[_j];
|
||||
if (func(child) === false) {
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +152,7 @@
|
||||
if (func(child) === false) {
|
||||
return false;
|
||||
}
|
||||
return crossScope || !(child instanceof Code) ? child.traverseChildren(crossScope, func) : undefined;
|
||||
return child.traverseChildren(crossScope, func);
|
||||
});
|
||||
};
|
||||
Base.prototype.invert = function() {
|
||||
@@ -247,22 +242,20 @@
|
||||
return code;
|
||||
};
|
||||
Expressions.prototype.compileExpression = function(node, o) {
|
||||
var compiledNode;
|
||||
var code;
|
||||
o.top = node.tags.front = true;
|
||||
this.tab = o.indent;
|
||||
node.tags.front = true;
|
||||
compiledNode = node.compile(merge(o, {
|
||||
top: true
|
||||
}));
|
||||
return node.isStatement(o) ? compiledNode : "" + (this.idt()) + compiledNode + ";";
|
||||
code = node.compile(o);
|
||||
return node.isStatement(o) ? code : this.tab + code + ';';
|
||||
};
|
||||
Expressions.wrap = function(nodes) {
|
||||
if (nodes.length === 1 && nodes[0] instanceof Expressions) {
|
||||
return nodes[0];
|
||||
}
|
||||
return new Expressions(nodes);
|
||||
};
|
||||
return Expressions;
|
||||
})();
|
||||
Expressions.wrap = function(nodes) {
|
||||
if (nodes.length === 1 && nodes[0] instanceof Expressions) {
|
||||
return nodes[0];
|
||||
}
|
||||
return new Expressions(nodes);
|
||||
};
|
||||
}).call(this);
|
||||
exports.Literal = (function() {
|
||||
Literal = (function() {
|
||||
function Literal(_arg) {
|
||||
@@ -282,18 +275,13 @@
|
||||
};
|
||||
Literal.prototype.isPureStatement = Literal.prototype.isStatement;
|
||||
Literal.prototype.isComplex = NO;
|
||||
Literal.prototype.isReserved = function() {
|
||||
return !!this.value.reserved;
|
||||
};
|
||||
Literal.prototype.assigns = function(name) {
|
||||
return name === this.value;
|
||||
};
|
||||
Literal.prototype.compileNode = function(o) {
|
||||
var end, idt, val;
|
||||
idt = this.isStatement(o) ? this.idt() : '';
|
||||
end = this.isStatement(o) ? ';' : '';
|
||||
val = this.isReserved() ? "\"" + this.value + "\"" : this.value;
|
||||
return idt + val + end;
|
||||
Literal.prototype.compileNode = function() {
|
||||
var val;
|
||||
val = this.value.reserved ? "\"" + this.value + "\"" : this.value;
|
||||
return this.isStatement() ? this.tab + val + ';' : val;
|
||||
};
|
||||
Literal.prototype.toString = function() {
|
||||
return ' "' + this.value + '"';
|
||||
@@ -317,10 +305,7 @@
|
||||
Return.prototype.compile = function(o) {
|
||||
var _ref2, expr;
|
||||
expr = ((_ref2 = this.expression) != null) ? _ref2.makeReturn() : undefined;
|
||||
if (expr && !(expr instanceof Return)) {
|
||||
return expr.compile(o);
|
||||
}
|
||||
return Return.__super__.compile.call(this, o);
|
||||
return expr && !(expr instanceof Return) ? expr.compile(o) : Return.__super__.compile.call(this, o);
|
||||
};
|
||||
Return.prototype.compileNode = function(o) {
|
||||
var expr;
|
||||
@@ -331,7 +316,7 @@
|
||||
}
|
||||
expr = ' ' + this.expression.compileBare(o);
|
||||
}
|
||||
return "" + this.tab + "return" + expr + ";";
|
||||
return this.tab + 'return' + expr + ';';
|
||||
};
|
||||
return Return;
|
||||
})();
|
||||
@@ -395,7 +380,7 @@
|
||||
Value.prototype.cacheReference = function(o) {
|
||||
var base, bref, name, nref;
|
||||
name = last(this.properties);
|
||||
if (!this.base.isComplex() && this.properties.length < 2 && !((name != null) ? name.isComplex() : undefined)) {
|
||||
if (this.properties.length < 2 && !this.base.isComplex() && !((name != null) ? name.isComplex() : undefined)) {
|
||||
return [this, this];
|
||||
}
|
||||
base = new Value(this.base, this.properties.slice(0, -1));
|
||||
|
||||
Reference in New Issue
Block a user