aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js38
1 files changed, 21 insertions, 17 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 7f1b46e3..ce0fbdd5 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2487,6 +2487,20 @@ merge(Compressor.prototype, {
// pass 3: we should drop declarations not in_use
var tt = new TreeTransformer(
function before(node, descend, in_list) {
+ var parent = tt.parent();
+ if (drop_vars) {
+ var sym = assign_as_unused(node);
+ if (sym instanceof AST_SymbolRef
+ && !(sym.definition().id in in_use_ids)) {
+ if (node instanceof AST_Assign) {
+ return maintain_this_binding(parent, node, node.right.transform(tt));
+ }
+ return make_node(AST_Number, node, {
+ value: 0
+ });
+ }
+ }
+ if (scope !== self) return;
if (node instanceof AST_Function
&& node.name
&& !compressor.option("keep_fnames")) {
@@ -2520,9 +2534,7 @@ merge(Compressor.prototype, {
def.eliminated++;
return make_node(AST_EmptyStatement, node);
}
- return node;
}
- var parent = tt.parent();
if (node instanceof AST_Definitions && !(parent instanceof AST_ForIn && parent.init === node)) {
// place uninitialized names at the start
var body = [], head = [], tail = [];
@@ -2602,18 +2614,6 @@ merge(Compressor.prototype, {
});
}
}
- if (drop_vars) {
- var sym = assign_as_unused(node);
- if (sym instanceof AST_SymbolRef
- && !(sym.definition().id in in_use_ids)) {
- if (node instanceof AST_Assign) {
- return maintain_this_binding(parent, node, node.right.transform(tt));
- }
- return make_node(AST_Number, node, {
- value: 0
- });
- }
- }
// certain combination of unused name + side effect leads to:
// https://github.com/mishoo/UglifyJS2/issues/44
// https://github.com/mishoo/UglifyJS2/issues/1830
@@ -2645,8 +2645,13 @@ merge(Compressor.prototype, {
}
return node;
}
- if (node instanceof AST_Scope && node !== self)
+ if (node instanceof AST_Scope) {
+ var save_scope = scope;
+ scope = node;
+ descend(node, this);
+ scope = save_scope;
return node;
+ }
function template(sym) {
return {
@@ -2662,8 +2667,7 @@ merge(Compressor.prototype, {
function scan_ref_scoped(node, descend) {
var sym;
- if (scope === self
- && (sym = assign_as_unused(node)) instanceof AST_SymbolRef
+ if ((sym = assign_as_unused(node)) instanceof AST_SymbolRef
&& self.variables.get(sym.name) === sym.definition()) {
if (node instanceof AST_Assign) node.right.walk(tw);
return true;