return self;
});
- OPT(AST_Lambda, function(self, compressor) {
- self.body = tighten_body(self.body, compressor);
- if (compressor.option("side_effects")
- && self.body.length == 1
- && self.body[0] === compressor.has_directive("use strict")) {
- self.body.length = 0;
- }
- return self;
- });
-
AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
if (!compressor.option("unused")) return;
if (compressor.has_directive("use asm")) return;
}
if (node instanceof AST_Call) calls_to_drop_args.push(node);
if (scope !== self) return;
- if (node instanceof AST_Function && node.name && drop_fn_name(node.name.definition())) {
- unused_fn_names.push(node);
- }
- if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
- var trim = compressor.drop_fargs(node, parent);
- for (var a = node.argnames, i = a.length; --i >= 0;) {
- var sym = a[i];
- if (!(sym.definition().id in in_use_ids)) {
- sym.__unused = true;
- if (trim) {
- log(sym, "Dropping unused function argument {name} [{file}:{line},{col}]", template(sym));
- a.pop();
- }
- } else {
- trim = false;
+ if (node instanceof AST_Lambda) {
+ if (drop_funcs && node !== self && node instanceof AST_Defun) {
+ var def = node.name.definition();
+ if (!(def.id in in_use_ids)) {
+ log(node.name, "Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
+ def.eliminated++;
+ return in_list ? List.skip : make_node(AST_EmptyStatement, node);
}
}
- fns_with_marked_args.push(node);
- }
- if (drop_funcs && node instanceof AST_Defun && node !== self) {
- var def = node.name.definition();
- if (!(def.id in in_use_ids)) {
- log(node.name, "Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
- def.eliminated++;
- return make_node(AST_EmptyStatement, node);
+ if (node instanceof AST_Function && node.name && drop_fn_name(node.name.definition())) {
+ unused_fn_names.push(node);
+ }
+ if (!(node instanceof AST_Accessor)) {
+ var trim = compressor.drop_fargs(node, parent);
+ for (var a = node.argnames, i = a.length; --i >= 0;) {
+ var sym = a[i];
+ if (!(sym.definition().id in in_use_ids)) {
+ sym.__unused = true;
+ if (trim) {
+ log(sym, "Dropping unused function argument {name} [{file}:{line},{col}]", template(sym));
+ a.pop();
+ }
+ } else {
+ trim = false;
+ }
+ }
+ fns_with_marked_args.push(node);
}
}
if (node instanceof AST_Definitions && !(parent instanceof AST_ForIn && parent.init === node)) {
// Certain combination of unused name + side effect leads to invalid AST:
// https://github.com/mishoo/UglifyJS2/issues/1830
// We fix it at this stage by moving the label inwards, back to the `for`.
- descend(node, this);
+ descend(node, tt);
if (node.body instanceof AST_BlockStatement) {
var block = node.body;
node.body = block.body.pop();
if (node instanceof AST_Scope) {
var save_scope = scope;
scope = node;
- descend(node, this);
+ descend(node, tt);
scope = save_scope;
return node;
}
});
tt.push(compressor.parent());
self.transform(tt);
+ if (self instanceof AST_Lambda
+ && self.body.length == 1
+ && self.body[0] instanceof AST_Directive
+ && self.body[0].value == "use strict") {
+ self.body.length = 0;
+ }
unused_fn_names.forEach(function(fn) {
fn.name = null;
});
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
"WARN: Dropping unused variable a [test/compress/issue-1034.js:4,20]",
"WARN: Dropping unused function nope [test/compress/issue-1034.js:11,21]",
- "INFO: pass 0: last_count: Infinity, count: 37",
+ "INFO: pass 0: last_count: Infinity, count: 36",
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
"INFO: Dropping unused variable b [test/compress/issue-1034.js:7,20]",
"INFO: Dropping unused variable c [test/compress/issue-1034.js:9,16]",
- "INFO: pass 1: last_count: 37, count: 18",
+ "INFO: pass 1: last_count: 36, count: 18",
]
}
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,16]",
"WARN: Dropping unused variable a [test/compress/issue-1034.js:5,20]",
"WARN: Dropping unused function nope [test/compress/issue-1034.js:12,21]",
- "INFO: pass 0: last_count: Infinity, count: 48",
+ "INFO: pass 0: last_count: Infinity, count: 47",
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:10,12]",
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
"INFO: Dropping unused variable b [test/compress/issue-1034.js:8,20]",
"INFO: Dropping unused variable c [test/compress/issue-1034.js:10,16]",
- "INFO: pass 1: last_count: 48, count: 29",
+ "INFO: pass 1: last_count: 47, count: 29",
]
}