remove the $self hack

operations are destructive anyway, so there's no point to clone the nodes in
the transformer.  speed++
This commit is contained in:
Mihai Bazon
2012-10-12 11:07:35 +03:00
parent 731fa9c236
commit 1b6f8d463f
2 changed files with 11 additions and 20 deletions

View File

@@ -57,9 +57,7 @@ function DEFNODE(type, props, methods, base) {
var proto = base && new base;
if (proto && proto.initialize || (methods && methods.initialize))
code += "this.initialize();";
code += " } ";
code += "if (!this.$self) this.$self = this;";
code += " } ";
code += "}}";
var ctor = new Function(code)();
if (proto) {
ctor.prototype = proto;
@@ -89,13 +87,12 @@ function DEFNODE(type, props, methods, base) {
var AST_Token = DEFNODE("Token", "type value line col pos endpos nlb comments_before file", {
}, null);
var AST_Node = DEFNODE("Node", "$self start end", {
var AST_Node = DEFNODE("Node", "start end", {
clone: function() {
return new this.CTOR(this);
},
$documentation: "Base class of all AST nodes",
$propdoc: {
$self: "[AST_Node] Reference to $self. Not modified by clone(). XXX: this could be removed.",
start: "[AST_Token] The first token of this node",
end: "[AST_Token] The last token of this node"
},
@@ -904,7 +901,7 @@ TreeWalker.prototype = {
},
in_boolean_context: function() {
var stack = this.stack;
var i = stack.length, self = stack[--i].$self;
var i = stack.length, self = stack[--i];
while (i > 0) {
var p = stack[--i];
if ((p instanceof AST_If && p.condition === self) ||
@@ -917,7 +914,7 @@ TreeWalker.prototype = {
}
if (!(p instanceof AST_Binary && (p.operator == "&&" || p.operator == "||")))
return false;
self = p.$self;
self = p;
}
},
loopcontrol_target: function(label) {
@@ -926,15 +923,15 @@ TreeWalker.prototype = {
for (var i = stack.length; --i >= 0;) {
var x = stack[i];
if (x instanceof AST_LabeledStatement && x.label.name == label.name) {
return x.body.$self;
return x.body;
}
}
} else {
for (var i = stack.length; --i >= 0;) {
var x = stack[i];
if (x instanceof AST_Switch) return x.$self;
if (x instanceof AST_Switch) return x;
if (x instanceof AST_For || x instanceof AST_ForIn || x instanceof AST_DWLoop) {
return (x.body instanceof AST_BlockStatement ? x.body : x).$self;
return (x.body instanceof AST_BlockStatement ? x.body : x);
}
}
}