From 1d407e761e72601fa607f884e0f53ced8ae4b94d Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 12 May 2017 04:51:44 +0800 Subject: fix invalid transform on `const` (#1919) - preserve (re)assignment to `const` for runtime error - suppress `cascade` on `const`, as runtime behaviour is ill-defined --- test/compress/collapse_vars.js | 46 ++++++++++++++++++++++++++++++++++++++++++ test/compress/drop-unused.js | 25 +++++++++++++++++++++++ test/compress/sequences.js | 24 ++++++++++++++++++++++ 3 files changed, 95 insertions(+) (limited to 'test') diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 4215cebe..0d578d7d 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -2186,3 +2186,49 @@ compound_assignment: { } expect_stdout: "4" } + +reassign_const_1: { + options = { + collapse_vars: true, + } + input: { + function f() { + const a = 1; + a = 2; + return a; + } + console.log(f()); + } + expect: { + function f() { + const a = 1; + a = 2; + return a; + } + console.log(f()); + } + expect_stdout: true +} + +reassign_const_2: { + options = { + collapse_vars: true, + } + input: { + function f() { + const a = 1; + ++a; + return a; + } + console.log(f()); + } + expect: { + function f() { + const a = 1; + ++a; + return a; + } + console.log(f()); + } + expect_stdout: true +} diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index ddf90bfa..96bd336c 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -1147,3 +1147,28 @@ var_catch_toplevel: { }(); } } + +reassign_const: { + options = { + cascade: true, + sequences: true, + side_effects: true, + unused: true, + } + input: { + function f() { + const a = 1; + a = 2; + return a; + } + console.log(f()); + } + expect: { + function f() { + const a = 1; + return a = 2, a; + } + console.log(f()); + } + expect_stdout: true +} diff --git a/test/compress/sequences.js b/test/compress/sequences.js index 10492565..9edf627e 100644 --- a/test/compress/sequences.js +++ b/test/compress/sequences.js @@ -710,3 +710,27 @@ issue_27: { })(jQuery); } } + +reassign_const: { + options = { + cascade: true, + sequences: true, + side_effects: true, + } + input: { + function f() { + const a = 1; + a++; + return a; + } + console.log(f()); + } + expect: { + function f() { + const a = 1; + return a++, a; + } + console.log(f()); + } + expect_stdout: true +} -- cgit v1.2.3