diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-10-12 11:07:35 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-10-12 11:07:35 +0300 |
commit | 1b6f8d463f15c5a3fa27b55be0a6d2dc74bcc12a (patch) | |
tree | 48b529e001623912051c47cc863cf124de125ca7 | |
parent | 731fa9c2360334d374593ea0a79031d24c9c7107 (diff) | |
download | tracifyjs-1b6f8d463f15c5a3fa27b55be0a6d2dc74bcc12a.tar.gz tracifyjs-1b6f8d463f15c5a3fa27b55be0a6d2dc74bcc12a.zip |
remove the $self hack
operations are destructive anyway, so there's no point to clone the nodes in
the transformer. speed++
-rw-r--r-- | lib/ast.js | 17 | ||||
-rw-r--r-- | lib/compress.js | 14 |
2 files changed, 11 insertions, 20 deletions
@@ -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); } } } diff --git a/lib/compress.js b/lib/compress.js index dadebe5e..c13421ea 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -80,7 +80,6 @@ merge(Compressor.prototype, { }, before: function(node, descend, in_list) { if (node._squeezed) return node; - this.stack[this.stack.length - 1] = node = node.clone(); if (node instanceof AST_Scope) { node.drop_unused(this); node = node.hoist_declarations(this); @@ -291,7 +290,7 @@ merge(Compressor.prototype, { var ab = aborts(stat.body); if (ab && ((ab instanceof AST_Return && !ab.value && in_lambda) - || (ab instanceof AST_Continue && self.$self === compressor.loopcontrol_target(ab.label)))) { + || (ab instanceof AST_Continue && self === compressor.loopcontrol_target(ab.label)))) { CHANGED = true; var body = as_statement_array(stat.body).slice(0, -1); stat = stat.clone(); @@ -308,7 +307,7 @@ merge(Compressor.prototype, { var ab = aborts(stat.alternative); if (ab && ((ab instanceof AST_Return && !ab.value && in_lambda) - || (ab instanceof AST_Continue && self.$self === compressor.loopcontrol_target(ab.label)))) { + || (ab instanceof AST_Continue && self === compressor.loopcontrol_target(ab.label)))) { CHANGED = true; stat = stat.clone(); stat.body = make_node(AST_BlockStatement, stat.body, { @@ -447,7 +446,6 @@ merge(Compressor.prototype, { stat.walk(new TreeWalker(function(node){ if (node instanceof AST_Definitions) { compressor.warn("Declarations in unreachable code! [{file}:{line},{col}]", node.start); - node = node.clone(); node.remove_initializers(); target.push(node); return true; @@ -1187,7 +1185,7 @@ merge(Compressor.prototype, { var last_branch = self.body[self.body.length - 1]; if (last_branch) { var stat = last_branch.body[last_branch.body.length - 1]; // last statement - if (stat instanceof AST_Break && compressor.loopcontrol_target(stat.label) === self.$self) + if (stat instanceof AST_Break && compressor.loopcontrol_target(stat.label) === self) last_branch.body.pop(); } return self; @@ -1204,11 +1202,7 @@ merge(Compressor.prototype, { }); AST_Definitions.DEFMETHOD("remove_initializers", function(){ - this.definitions = this.definitions.map(function(def){ - def = def.clone(); - def.value = null; - return def; - }); + this.definitions.forEach(function(def){ def.value = null }); }); AST_Definitions.DEFMETHOD("to_assignments", function(){ |