aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-24 02:55:32 +0800
committerGitHub <noreply@github.com>2017-03-24 02:55:32 +0800
commite918748d88e39c6f2142b01e71c3e580d790d642 (patch)
treee8df63c176d67d82f7bc3f5a6df7e99091248a4d /test/compress
parent6b2f34769a5572bdd9db034f19bbc2a0b6e6dabb (diff)
downloadtracifyjs-e918748d88e39c6f2142b01e71c3e580d790d642.tar.gz
tracifyjs-e918748d88e39c6f2142b01e71c3e580d790d642.zip
improve collapsible value detection (#1638)
- #1634 bars variables with cross-scope references in between to collapse - but if assigned value is side-effect-free, no states can be modified, so it is safe to move
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/collapse_vars.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 6f273b97..2437ca5f 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -1522,3 +1522,71 @@ issue_1631_3: {
}
expect_stdout: "6"
}
+
+var_side_effects_1: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var print = console.log.bind(console);
+ function foo(x) {
+ var twice = x * 2;
+ print('Foo:', twice);
+ }
+ foo(10);
+ }
+ expect: {
+ var print = console.log.bind(console);
+ function foo(x) {
+ print('Foo:', 2 * x);
+ }
+ foo(10);
+ }
+ expect_stdout: true
+}
+
+var_side_effects_2: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var print = console.log.bind(console);
+ function foo(x) {
+ var twice = x.y * 2;
+ print('Foo:', twice);
+ }
+ foo({ y: 10 });
+ }
+ expect: {
+ var print = console.log.bind(console);
+ function foo(x) {
+ var twice = 2 * x.y;
+ print('Foo:', twice);
+ }
+ foo({ y: 10 });
+ }
+ expect_stdout: true
+}
+
+var_side_effects_3: {
+ options = {
+ collapse_vars: true,
+ pure_getters: true,
+ }
+ input: {
+ var print = console.log.bind(console);
+ function foo(x) {
+ var twice = x.y * 2;
+ print('Foo:', twice);
+ }
+ foo({ y: 10 });
+ }
+ expect: {
+ var print = console.log.bind(console);
+ function foo(x) {
+ print('Foo:', 2 * x.y);
+ }
+ foo({ y: 10 });
+ }
+ expect_stdout: true
+}