From baf4903aa7c36bd614d3547403d6794bf77ab472 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 3 Oct 2020 00:02:28 +0100 Subject: fix corner cases of `catch` variable inlining (#4169) --- test/compress/drop-unused.js | 31 +++++++++++++ test/compress/functions.js | 39 ++++++++++++++++ test/compress/ie8.js | 105 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) (limited to 'test') 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 +} -- cgit v1.2.3