[Pkg-javascript-commits] [uglifyjs] 409/491: patch variable declaractions extracted within `catch` (#2753)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:58 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit 2972d58dbb7cdb918267b278368550bf36c3cb08
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Tue Jan 9 13:54:35 2018 +0800
patch variable declaractions extracted within `catch` (#2753)
fixes #2749
---
lib/compress.js | 15 +++++++++++++--
test/compress/collapse_vars.js | 1 +
test/compress/dead-code.js | 29 +++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 7016365..406a331 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3774,9 +3774,20 @@ merge(Compressor.prototype, {
OPT(AST_Try, function(self, compressor){
tighten_body(self.body, compressor);
if (self.bcatch && self.bfinally && all(self.bfinally.body, is_empty)) self.bfinally = null;
- if (all(self.body, is_empty)) {
+ if (compressor.option("dead_code") && all(self.body, is_empty)) {
var body = [];
- if (self.bcatch) extract_declarations_from_unreachable_code(compressor, self.bcatch, body);
+ if (self.bcatch) {
+ extract_declarations_from_unreachable_code(compressor, self.bcatch, body);
+ body.forEach(function(stat) {
+ if (!(stat instanceof AST_Definitions)) return;
+ stat.definitions.forEach(function(var_def) {
+ var def = var_def.name.definition().redefined();
+ if (!def) return;
+ var_def.name = var_def.name.clone();
+ var_def.name.thedef = def;
+ });
+ });
+ }
if (self.bfinally) body = body.concat(self.bfinally.body);
return make_node(AST_BlockStatement, self, {
body: body
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 0bad06a..12b4923 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2197,6 +2197,7 @@ toplevel_single_reference: {
unused_orig: {
options = {
collapse_vars: true,
+ dead_code: true,
passes: 2,
reduce_funcs: true,
reduce_vars: true,
diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js
index 490cff7..afc8c56 100644
--- a/test/compress/dead-code.js
+++ b/test/compress/dead-code.js
@@ -833,3 +833,32 @@ issue_2701: {
}
expect_stdout: "function"
}
+
+issue_2749: {
+ options = {
+ dead_code: true,
+ inline: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = 2, c = "PASS";
+ while (a--)
+ (function() {
+ return b ? c = "FAIL" : b = 1;
+ try {
+ } catch (b) {
+ var b;
+ }
+ })();
+ console.log(c);
+ }
+ expect: {
+ var a = 2, c = "PASS";
+ while (a--)
+ b = void 0, b ? c = "FAIL" : b = 1;
+ var b;
+ console.log(c);
+ }
+ expect_stdout: "PASS"
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list