aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-10-03 00:02:28 +0100
committerGitHub <noreply@github.com>2020-10-03 07:02:28 +0800
commitbaf4903aa7c36bd614d3547403d6794bf77ab472 (patch)
tree3dfa234e6adb17920356e82b0abbf03563a50e40 /test
parent35465d590eda4074fd9df0e640a8c0934e760d9b (diff)
downloadtracifyjs-baf4903aa7c36bd614d3547403d6794bf77ab472.tar.gz
tracifyjs-baf4903aa7c36bd614d3547403d6794bf77ab472.zip
fix corner cases of `catch` variable inlining (#4169)
Diffstat (limited to 'test')
-rw-r--r--test/compress/drop-unused.js31
-rw-r--r--test/compress/functions.js39
-rw-r--r--test/compress/ie8.js105
3 files changed, 175 insertions, 0 deletions
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 0b76f6f6..160b96b4 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -2992,3 +2992,34 @@ issue_4146: {
}
expect_stdout: "function"
}
+
+single_use_catch_redefined: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = 1;
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ }
+ console.log(g());
+ }
+ expect: {
+ var a = 1;
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ }
+ console.log(g());
+ }
+ expect_stdout: true
+}
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 0cd07dda..13368169 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -4853,3 +4853,42 @@ direct_inline: {
}
expect_stdout: "21"
}
+
+direct_inline_catch_redefined: {
+ options = {
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ }
+ input: {
+ var a = 1;
+ function f() {
+ return a;
+ }
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ console.log(a, f(), g());
+ }
+ console.log(a, f(), g());
+ }
+ expect: {
+ var a = 1;
+ function f() {
+ return a;
+ }
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ console.log(a, f(), g());
+ }
+ console.log(a, a, g());
+ }
+ expect_stdout: true
+}
diff --git a/test/compress/ie8.js b/test/compress/ie8.js
index 6c0aa9e8..4d74d44e 100644
--- a/test/compress/ie8.js
+++ b/test/compress/ie8.js
@@ -2714,3 +2714,108 @@ issue_2737: {
}
expect_stdout: "function"
}
+
+single_use_catch_redefined: {
+ options = {
+ ie8: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = 1;
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ }
+ console.log(g());
+ }
+ expect: {
+ var a = 1;
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ }
+ console.log(g());
+ }
+ expect_stdout: true
+}
+
+single_use_inline_catch_redefined: {
+ options = {
+ ie8: true,
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = 1;
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ }
+ console.log(g());
+ }
+ expect: {
+ var a = 1;
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ }
+ console.log(g());
+ }
+ expect_stdout: true
+}
+
+direct_inline_catch_redefined: {
+ options = {
+ ie8: true,
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ }
+ input: {
+ var a = 1;
+ function f() {
+ return a;
+ }
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ console.log(a, f(), g());
+ }
+ console.log(a, f(), g());
+ }
+ expect: {
+ var a = 1;
+ function f() {
+ return a;
+ }
+ try {
+ throw 2;
+ } catch (a) {
+ function g() {
+ return a;
+ }
+ console.log(a, f(), g());
+ }
+ console.log(a, a, g());
+ }
+ expect_stdout: true
+}