aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-07-20 16:28:13 +0100
committerGitHub <noreply@github.com>2020-07-20 23:28:13 +0800
commita5db8cd14c55aa64cb6e5cfb4f98f87aa38504dd (patch)
tree3111a63135e2659e51f2a8096e9d6b732f3c53e9
parent2021c2fa3e616da497f8fc305010c9c1dd1a67de (diff)
downloadtracifyjs-a5db8cd14c55aa64cb6e5cfb4f98f87aa38504dd.tar.gz
tracifyjs-a5db8cd14c55aa64cb6e5cfb4f98f87aa38504dd.zip
fix corner case in `collapse_vars` (#4013)
fixes #4012
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/collapse_vars.js37
2 files changed, 40 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 2c8c7769..a464b664 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1197,7 +1197,9 @@ merge(Compressor.prototype, {
function find_loop_scope_try() {
var node = compressor.self(), level = 0;
do {
- if (node instanceof AST_Catch || node instanceof AST_Finally) {
+ if (node instanceof AST_Catch) {
+ if (!compressor.parent(level).bfinally) level++;
+ } else if (node instanceof AST_Finally) {
level++;
} else if (node instanceof AST_IterationStatement) {
in_loop = true;
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index dcc95b23..109bbde0 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -8280,3 +8280,40 @@ issue_3976: {
}
expect_stdout: "PASS"
}
+
+issue_4012: {
+ options = {
+ collapse_vars: true,
+ dead_code: true,
+ evaluate: true,
+ }
+ input: {
+ (function(a) {
+ try {
+ throw 2;
+ } catch (b) {
+ a = "PASS";
+ if (--b)
+ return;
+ if (3);
+ } finally {
+ console.log(a);
+ }
+ })();
+ }
+ expect: {
+ (function(a) {
+ try {
+ throw 2;
+ } catch (b) {
+ a = "PASS";
+ if (--b)
+ return;
+ if (3);
+ } finally {
+ console.log(a);
+ }
+ })();
+ }
+ expect_stdout: "PASS"
+}