aboutsummaryrefslogtreecommitdiff
path: root/test/compress/collapse_vars.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-23 07:17:34 +0800
committerGitHub <noreply@github.com>2017-03-23 07:17:34 +0800
commit48ffbef51d914824916f387d756b263c341f032e (patch)
tree33529fa57d7a7d54bf0d87fc1f1db6d906b13de0 /test/compress/collapse_vars.js
parentc0f3feae9f251abbea5ae1198e1a6784dd3261f7 (diff)
downloadtracifyjs-48ffbef51d914824916f387d756b263c341f032e.tar.gz
tracifyjs-48ffbef51d914824916f387d756b263c341f032e.zip
account for cross-scope modifications in `collapse_vars` (#1634)
mostly done by @kzc fixes #1631
Diffstat (limited to 'test/compress/collapse_vars.js')
-rw-r--r--test/compress/collapse_vars.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 5a7c001f..6f273b97 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -1415,3 +1415,110 @@ issue_1605_2: {
(new Object).p = 1;
}
}
+
+issue_1631_1: {
+ options = {
+ cascade: true,
+ collapse_vars: true,
+ hoist_funs: true,
+ join_vars: true,
+ sequences: true,
+ side_effects: true,
+ }
+ input: {
+ var pc = 0;
+ function f(x) {
+ pc = 200;
+ return 100;
+ }
+ function x() {
+ var t = f();
+ pc += t;
+ return pc;
+ }
+ console.log(x());
+ }
+ expect: {
+ function f(x) {
+ return pc = 200, 100;
+ }
+ function x() {
+ var t = f();
+ return pc += t;
+ }
+ var pc = 0;
+ console.log(x());
+ }
+ expect_stdout: "300"
+}
+
+issue_1631_2: {
+ options = {
+ cascade: true,
+ collapse_vars: true,
+ hoist_funs: true,
+ join_vars: true,
+ sequences: true,
+ side_effects: true,
+ }
+ input: {
+ var a = 0, b = 1;
+ function f() {
+ a = 2;
+ return 4;
+ }
+ function g() {
+ var t = f();
+ b = a + t;
+ return b;
+ }
+ console.log(g());
+ }
+ expect: {
+ function f() {
+ return a = 2, 4;
+ }
+ function g() {
+ var t = f();
+ return b = a + t;
+ }
+ var a = 0, b = 1;
+ console.log(g());
+ }
+ expect_stdout: "6"
+}
+
+issue_1631_3: {
+ options = {
+ cascade: true,
+ collapse_vars: true,
+ hoist_funs: true,
+ join_vars: true,
+ sequences: true,
+ side_effects: true,
+ }
+ input: {
+ function g() {
+ var a = 0, b = 1;
+ function f() {
+ a = 2;
+ return 4;
+ }
+ var t = f();
+ b = a + t;
+ return b;
+ }
+ console.log(g());
+ }
+ expect: {
+ function g() {
+ function f() {
+ return a = 2, 4;
+ }
+ var a = 0, b = 1, t = f();
+ return b = a + t;
+ }
+ console.log(g());
+ }
+ expect_stdout: "6"
+}