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();
- AST_Node[sym.unreferenced() ? "warn" : "info"]("Dropping unused function argument {name} [{file}:{line},{col}]", template(sym));
}
} else {
trim = false;
if (drop_funcs && node instanceof AST_Defun && node !== self) {
var def = node.name.definition();
if (!(def.id in in_use_ids)) {
- AST_Node[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
+ log(node.name, "Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
def.eliminated++;
return make_node(AST_EmptyStatement, node);
}
AST_Node.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", template(def.name));
side_effects.push(value);
} else {
- AST_Node[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", template(def.name));
+ log(def.name, "Dropping unused variable {name} [{file}:{line},{col}]", template(def.name));
}
sym.eliminated++;
}
return node;
}
+ function log(sym, text, props) {
+ AST_Node[sym.unreferenced() ? "warn" : "info"](text, props);
+ }
+
function template(sym) {
return {
name : sym.name,
if (stat instanceof AST_SimpleStatement) {
return make_node(AST_UnaryPrefix, stat, {
operator: "void",
- expression: stat.body.clone(true)
+ expression: stat.body
});
}
}
expect_stdout: "PASS"
}
-issue_3400: {
+issue_3400_1: {
options = {
collapse_vars: true,
inline: true,
return g;
});
}
+ expect: {
+ void console.log(function() {
+ function g() {
+ function h(u) {
+ var o = {
+ p: u
+ };
+ return console.log(o[g]), o;
+ }
+ function e() {
+ return [ 42 ].map(function(v) {
+ return h(v);
+ });
+ }
+ return e();
+ }
+ return g;
+ }()()[0].p);
+ }
+ expect_stdout: [
+ "undefined",
+ "42",
+ ]
+}
+
+issue_3400_2: {
+ options = {
+ collapse_vars: true,
+ inline: true,
+ passes: 2,
+ reduce_funcs: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function(f) {
+ console.log(f()()[0].p);
+ })(function() {
+ function g() {
+ function h(u) {
+ var o = {
+ p: u
+ };
+ return console.log(o[g]), o;
+ }
+ function e() {
+ return [ 42 ].map(function(v) {
+ return h(v);
+ });
+ }
+ return e();
+ }
+ return g;
+ });
+ }
expect: {
void console.log(function g() {
- function e() {
- return [42].map(function(v) {
- return o = {
- p: v
- }, console.log(o[g]) , o;
- var o;
- });
- }
- return e();
+ return [ 42 ].map(function(v) {
+ return function(u) {
+ var o = {
+ p: u
+ };
+ return console.log(o[g]), o;
+ }(v);
+ });
}()[0].p);
}
expect_stdout: [
}
expect_stdout: "PASS"
}
+
+issue_3506_1: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ inline: true,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function(b) {
+ (function(b) {
+ b && (a = "PASS");
+ })(b);
+ })(a);
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ !function(b) {
+ b && (a = "PASS");
+ }(a);
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_3506_2: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ inline: true,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function(b) {
+ (function(c) {
+ var d = 1;
+ for (;c && (a = "PASS") && 0 < --d;);
+ })(b);
+ })(a);
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ !function(c) {
+ var d = 1;
+ for (;c && (a = "PASS") && 0 < --d;);
+ }(a);
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_3506_3: {
+ options = {
+ collapse_vars: true,
+ dead_code: true,
+ evaluate: true,
+ inline: true,
+ loops: true,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function(b) {
+ (function(c) {
+ var d = 1;
+ for (;c && (a = "PASS") && 0 < --d;);
+ })(b);
+ })(a);
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ !function(c) {
+ var d = 1;
+ for (;c && (a = "PASS") && 0 < --d;);
+ }(a);
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+}