From d819559a01fca28921a9b93cb1f4127b6ea3306b Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 29 Dec 2017 14:04:52 +0800 Subject: [PATCH 1/3] minor clean-ups (#2686) --- lib/compress.js | 2 +- lib/output.js | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 4e3a8f82..318246cd 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3998,7 +3998,7 @@ merge(Compressor.prototype, { } if (defs) defs.push(arg.definition()); } - return !defs || defs.length == 0 || !is_reachable(fn.body[0], defs); + return !defs || defs.length == 0 || !is_reachable(stat, defs); } function flatten_args(fn) { diff --git a/lib/output.js b/lib/output.js index fc592d60..58521e3c 100644 --- a/lib/output.js +++ b/lib/output.js @@ -671,9 +671,7 @@ function OutputStream(options) { } }; - PARENS(AST_Node, function(){ - return false; - }); + PARENS(AST_Node, return_false); // a function expression needs parens around it when it's provably // the first token to appear in a statement. @@ -699,9 +697,7 @@ function OutputStream(options) { // same goes for an object literal, because otherwise it would be // interpreted as a block of code. - PARENS(AST_Object, function(output){ - return first_in_statement(output); - }); + PARENS(AST_Object, first_in_statement); PARENS(AST_Unary, function(output){ var p = output.parent(); From ed7a0a454e9c06c592a0dd40ea740faadc0bb4c0 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 30 Dec 2017 15:20:25 +0800 Subject: [PATCH 2/3] fix `dead_code` on escaped `return` assignment (#2693) fixes #2692 --- lib/compress.js | 8 ++++---- test/compress/dead-code.js | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 318246cd..b94e5847 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4838,7 +4838,7 @@ merge(Compressor.prototype, { return self; }); - function is_reachable(node, defs) { + function is_reachable(self, defs) { var reachable = false; var find_ref = new TreeWalker(function(node) { if (reachable) return true; @@ -4848,7 +4848,7 @@ merge(Compressor.prototype, { }); var scan_scope = new TreeWalker(function(node) { if (reachable) return true; - if (node instanceof AST_Scope) { + if (node instanceof AST_Scope && node !== self) { var parent = scan_scope.parent(); if (!(parent instanceof AST_Call && parent.expression === node)) { node.walk(find_ref); @@ -4856,7 +4856,7 @@ merge(Compressor.prototype, { return true; } }); - node.walk(scan_scope); + self.walk(scan_scope); return reachable; } @@ -4873,7 +4873,7 @@ merge(Compressor.prototype, { parent = compressor.parent(level++); if (parent instanceof AST_Exit) { if (in_try(level, parent instanceof AST_Throw)) break; - if (is_reachable(self, [ def ])) break; + if (is_reachable(def.scope, [ def ])) break; if (self.operator == "=") return self.right; return make_node(AST_Binary, self, { operator: self.operator.slice(0, -1), diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index 7ea380d2..68ee4b12 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -855,3 +855,29 @@ issue_2666: { } expect_stdout: "object" } + +issue_2692: { + options = { + dead_code: true, + reduce_vars: false, + } + input: { + function f(a) { + return a = g; + function g() { + return a; + } + } + console.log(typeof f()()); + } + expect: { + function f(a) { + return a = g; + function g() { + return a; + } + } + console.log(typeof f()()); + } + expect_stdout: "function" +} From e2ec270b04ddefc1c7aa39ab1eb24f2cae0077a8 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 31 Dec 2017 00:01:14 +0800 Subject: [PATCH 3/3] v3.3.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 57cf640b..74878c08 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "homepage": "http://lisperator.net/uglifyjs", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", - "version": "3.3.3", + "version": "3.3.4", "engines": { "node": ">=0.8.0" },