aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-05-12 04:51:44 +0800
committerGitHub <noreply@github.com>2017-05-12 04:51:44 +0800
commit1d407e761e72601fa607f884e0f53ced8ae4b94d (patch)
treec0d858a4d0d90c610337fdf37f0ba9e3e6a91dea /test
parent2b44f4ae30921e3d1eea2846250f26b0942490df (diff)
downloadtracifyjs-1d407e761e72601fa607f884e0f53ced8ae4b94d.tar.gz
tracifyjs-1d407e761e72601fa607f884e0f53ced8ae4b94d.zip
fix invalid transform on `const` (#1919)
- preserve (re)assignment to `const` for runtime error - suppress `cascade` on `const`, as runtime behaviour is ill-defined
Diffstat (limited to 'test')
-rw-r--r--test/compress/collapse_vars.js46
-rw-r--r--test/compress/drop-unused.js25
-rw-r--r--test/compress/sequences.js24
3 files changed, 95 insertions, 0 deletions
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
+}