aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai.bazon@gmail.com>2013-10-23 13:58:09 -0700
committerMihai Bazon <mihai.bazon@gmail.com>2013-10-23 13:58:09 -0700
commit63e1a8e1fd17958557f41a55ea08d678b7995f9b (patch)
tree45b3ac9da3ecfd3f8bbadf0768f9c4afa202f5ce /lib/compress.js
parentaafe2e1db385f4e087b0c6140ead490ef5ccae72 (diff)
parent7055af822147bcf36421ce02fd3447e7f916ce2e (diff)
downloadtracifyjs-63e1a8e1fd17958557f41a55ea08d678b7995f9b.tar.gz
tracifyjs-63e1a8e1fd17958557f41a55ea08d678b7995f9b.zip
Merge pull request #323 from rvanvelzen/undefined-drop-vars-fix
Fix #280
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js30
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/compress.js b/lib/compress.js
index b79a5088..083b5d29 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -86,13 +86,14 @@ merge(Compressor.prototype, {
before: function(node, descend, in_list) {
if (node._squeezed) return node;
if (node instanceof AST_Scope) {
- node.drop_unused(this);
+ //node.drop_unused(this);
node = node.hoist_declarations(this);
}
descend(node, this);
node = node.optimize(this);
if (node instanceof AST_Scope) {
node.drop_unused(this);
+ descend(node, this);
}
node._squeezed = true;
return node;
@@ -1082,18 +1083,23 @@ merge(Compressor.prototype, {
}
return node;
}
- if (node instanceof AST_For && node.init instanceof AST_BlockStatement) {
+ if (node instanceof AST_For) {
descend(node, this);
- // certain combination of unused name + side effect leads to:
- // https://github.com/mishoo/UglifyJS2/issues/44
- // that's an invalid AST.
- // We fix it at this stage by moving the `var` outside the `for`.
- var body = node.init.body.slice(0, -1);
- node.init = node.init.body.slice(-1)[0].body;
- body.push(node);
- return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
- body: body
- });
+
+ if (node.init instanceof AST_BlockStatement) {
+ // certain combination of unused name + side effect leads to:
+ // https://github.com/mishoo/UglifyJS2/issues/44
+ // that's an invalid AST.
+ // We fix it at this stage by moving the `var` outside the `for`.
+
+ var body = node.init.body.slice(0, -1);
+ node.init = node.init.body.slice(-1)[0].body;
+ body.push(node);
+
+ return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
+ body: body
+ });
+ }
}
if (node instanceof AST_Scope && node !== self)
return node;