diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-04-17 19:53:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-18 02:53:26 +0800 |
commit | da68ec6e190e8969741606b2b2a3eb2d327061ba (patch) | |
tree | 17aa71636bf7a44155e70626526ecfb980f830c3 /test/compress | |
parent | 15a3ebd467ea1f88b55affb0c3cc2d218fad3718 (diff) | |
download | tracifyjs-da68ec6e190e8969741606b2b2a3eb2d327061ba.tar.gz tracifyjs-da68ec6e190e8969741606b2b2a3eb2d327061ba.zip |
fix corner cases in `join_vars` (#3790)
fixes #3789
fixes #3791
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/collapse_vars.js | 2 | ||||
-rw-r--r-- | test/compress/join_vars.js | 119 |
2 files changed, 120 insertions, 1 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index a9167262..fd421a20 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -804,7 +804,7 @@ collapse_vars_assignment: { function log(x) { return console.log(x), x; } function f0(c) { var a = 3 / c; - return a; + return a = a; } function f1(c) { return 1 - 3 / c; diff --git a/test/compress/join_vars.js b/test/compress/join_vars.js index bfbebdef..9901c486 100644 --- a/test/compress/join_vars.js +++ b/test/compress/join_vars.js @@ -663,3 +663,122 @@ issue_3788: { "PASS", ] } + +issue_3789_1: { + options = { + join_vars: true, + } + input: { + try { + c; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + try {} catch (c) { + var a; + c = 0; + } + } + expect: { + try { + c; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + try {} catch (c) { + var a; + c = 0; + } + } + expect_stdout: "PASS" +} + +issue_3789_2: { + options = { + join_vars: true, + } + input: { + try { + c; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + try {} catch (c) { + try {} catch (c) { + var a; + c = 0; + } + } + } + expect: { + try { + c; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + try {} catch (c) { + try {} catch (c) { + var a; + c = 0; + } + } + } + expect_stdout: "PASS" +} + +issue_3791_1: { + options = { + collapse_vars: true, + join_vars: true, + toplevel: true, + } + input: { + var a = "PASS"; + switch (a) { + case console: + } + var a = a; + console.log(a); + } + expect: { + var a; + switch (a = "PASS") { + case console: + } + var a = a; + console.log(a); + } + expect_stdout: "PASS" +} + +issue_3791_2: { + options = { + collapse_vars: true, + join_vars: true, + } + input: { + function f(a) { + var b; + return b = a || g; + function g() { + return b; + } + } + console.log(typeof f()()); + } + expect: { + function f(a) { + var b; + return b = a || g; + function g() { + return b; + } + } + console.log(typeof f()()); + } + expect_stdout: "function" +} |