mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
nodes: made ExistenceNode omit typeof for known variables
This commit is contained in:
34
lib/nodes.js
34
lib/nodes.js
@@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, InNode, IndexNode, LiteralNode, NO, NUMBER, ObjectNode, OpNode, ParamNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SIMPLENUM, Scope, SliceNode, SplatNode, SwitchNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, YES, _ref, compact, del, ends, flatten, include, indexOf, last, literal, merge, starts, utility;
|
||||
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, InNode, IndexNode, LiteralNode, NO, NUMBER, ObjectNode, OpNode, ParamNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SIMPLENUM, Scope, SliceNode, SplatNode, SwitchNode, TAB, THIS, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, YES, _ref, compact, del, ends, flatten, include, indexOf, last, literal, merge, starts, utility;
|
||||
var __extends = function(child, parent) {
|
||||
var ctor = function(){};
|
||||
ctor.prototype = parent.prototype;
|
||||
@@ -16,6 +16,9 @@
|
||||
NO = function() {
|
||||
return false;
|
||||
};
|
||||
THIS = function() {
|
||||
return this;
|
||||
};
|
||||
exports.BaseNode = (function() {
|
||||
BaseNode = function() {
|
||||
this.tags = {};
|
||||
@@ -148,9 +151,7 @@
|
||||
};
|
||||
BaseNode.prototype["class"] = 'BaseNode';
|
||||
BaseNode.prototype.children = [];
|
||||
BaseNode.prototype.unwrap = function() {
|
||||
return this;
|
||||
};
|
||||
BaseNode.prototype.unwrap = THIS;
|
||||
BaseNode.prototype.isStatement = NO;
|
||||
BaseNode.prototype.isPureStatement = NO;
|
||||
BaseNode.prototype.isComplex = YES;
|
||||
@@ -281,9 +282,7 @@
|
||||
ReturnNode.prototype.isStatement = YES;
|
||||
ReturnNode.prototype.isPureStatement = YES;
|
||||
ReturnNode.prototype.children = ['expression'];
|
||||
ReturnNode.prototype.makeReturn = function() {
|
||||
return this;
|
||||
};
|
||||
ReturnNode.prototype.makeReturn = THIS;
|
||||
ReturnNode.prototype.compile = function(o) {
|
||||
var expr;
|
||||
expr = this.expression.makeReturn();
|
||||
@@ -337,10 +336,10 @@
|
||||
return this.properties.length ? this : this.base;
|
||||
};
|
||||
ValueNode.prototype.isStatement = function(o) {
|
||||
return this.base.isStatement && this.base.isStatement(o) && !this.hasProperties();
|
||||
return this.base.isStatement(o) && !this.properties.length;
|
||||
};
|
||||
ValueNode.prototype.isNumber = function() {
|
||||
return this.base instanceof LiteralNode && this.base.value.match(NUMBER);
|
||||
return this.base instanceof LiteralNode && NUMBER.test(this.base.value);
|
||||
};
|
||||
ValueNode.prototype.cacheIndexes = function(o) {
|
||||
var _len, _ref2, _ref3, copy, first, i, index, indexVar, prop;
|
||||
@@ -421,9 +420,7 @@
|
||||
__extends(CommentNode, BaseNode);
|
||||
CommentNode.prototype["class"] = 'CommentNode';
|
||||
CommentNode.prototype.isStatement = YES;
|
||||
CommentNode.prototype.makeReturn = function() {
|
||||
return this;
|
||||
};
|
||||
CommentNode.prototype.makeReturn = THIS;
|
||||
CommentNode.prototype.compileNode = function(o) {
|
||||
return this.tab + '/*' + this.comment.replace(/\n/g, '\n' + this.tab) + '*/';
|
||||
};
|
||||
@@ -1207,14 +1204,14 @@
|
||||
exports.WhileNode = (function() {
|
||||
WhileNode = function(condition, opts) {
|
||||
WhileNode.__super__.constructor.call(this);
|
||||
if (opts && opts.invert) {
|
||||
if (opts == null ? undefined : opts.invert) {
|
||||
if (condition instanceof OpNode) {
|
||||
condition = new ParentheticalNode(condition);
|
||||
}
|
||||
condition = new OpNode('!', condition);
|
||||
}
|
||||
this.condition = condition;
|
||||
this.guard = opts && opts.guard;
|
||||
this.guard = opts == null ? undefined : opts.guard;
|
||||
return this;
|
||||
};
|
||||
__extends(WhileNode, BaseNode);
|
||||
@@ -1465,9 +1462,7 @@
|
||||
ThrowNode.prototype["class"] = 'ThrowNode';
|
||||
ThrowNode.prototype.children = ['expression'];
|
||||
ThrowNode.prototype.isStatement = YES;
|
||||
ThrowNode.prototype.makeReturn = function() {
|
||||
return this;
|
||||
};
|
||||
ThrowNode.prototype.makeReturn = THIS;
|
||||
ThrowNode.prototype.compileNode = function(o) {
|
||||
return "" + (this.tab) + "throw " + (this.expression.compile(o)) + ";";
|
||||
};
|
||||
@@ -1485,14 +1480,15 @@
|
||||
ExistenceNode.prototype.compileNode = function(o) {
|
||||
var test;
|
||||
test = ExistenceNode.compileTest(o, this.expression)[0];
|
||||
return this.parenthetical ? test.substring(1, test.length - 1) : test;
|
||||
return this.parenthetical ? test.slice(1, -1) : test;
|
||||
};
|
||||
ExistenceNode.compileTest = function(o, variable) {
|
||||
var _ref2, first, second;
|
||||
_ref2 = variable.compileReference(o, {
|
||||
precompile: true
|
||||
}), first = _ref2[0], second = _ref2[1];
|
||||
return [("(typeof " + (first) + " !== \"undefined\" && " + (second) + " !== null)"), second];
|
||||
first = first === second && o.scope.check(first) ? ("(" + (first) + " != null)") : ("(typeof " + (first) + " !== \"undefined\" && " + (second) + " !== null)");
|
||||
return [first, second];
|
||||
};
|
||||
return ExistenceNode;
|
||||
}).call(this);
|
||||
|
||||
Reference in New Issue
Block a user