aboutsummaryrefslogtreecommitdiff
path: root/test/compress/collapse_vars.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-10-18 02:54:51 +0800
committerGitHub <noreply@github.com>2017-10-18 02:54:51 +0800
commit7e5b5cac97a71d0eb0d23f0cba7554e8a9eec179 (patch)
tree8647120da91d2c81c4e1a4a1e17e8eac1461d060 /test/compress/collapse_vars.js
parentc1346e06b70806995f3b75919d35bf5348ce88ed (diff)
downloadtracifyjs-7e5b5cac97a71d0eb0d23f0cba7554e8a9eec179.tar.gz
tracifyjs-7e5b5cac97a71d0eb0d23f0cba7554e8a9eec179.zip
fix `AST_PropAccess` in `collapse_vars` (take 3) (#2375)
Suppress scanning beyond assignment to `a.b`
Diffstat (limited to 'test/compress/collapse_vars.js')
-rw-r--r--test/compress/collapse_vars.js168
1 files changed, 168 insertions, 0 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index c115763c..13fff97a 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2783,3 +2783,171 @@ issue_2364_4: {
}
expect_stdout: "1 0"
}
+
+issue_2364_5: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ pure_getters: true,
+ properties: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ function f0(o, a, h) {
+ var b = 3 - a;
+ var obj = o;
+ var seven = 7;
+ var prop = 'run';
+ var t = obj[prop](b)[seven] = h;
+ return t;
+ }
+ }
+ expect: {
+ function f0(o, a, h) {
+ return o.run(3 - a)[7] = h;
+ }
+ }
+}
+
+issue_2364_6: {
+ options = {
+ collapse_vars: true,
+ pure_getters: true,
+ }
+ input: {
+ function f(a, b) {
+ var c = a.p;
+ b.p = "FAIL";
+ return c;
+ }
+ var o = {
+ p: "PASS"
+ }
+ console.log(f(o, o));
+ }
+ expect: {
+ function f(a, b) {
+ var c = a.p;
+ b.p = "FAIL";
+ return c;
+ }
+ var o = {
+ p: "PASS"
+ }
+ console.log(f(o, o));
+ }
+ expect_stdout: "PASS"
+}
+
+issue_2364_7: {
+ options = {
+ collapse_vars: true,
+ pure_getters: true,
+ }
+ input: {
+ function f(a, b) {
+ var c = a.p;
+ b.f();
+ return c;
+ }
+ var o = {
+ p: "PASS",
+ f: function() {
+ this.p = "FAIL";
+ }
+ }
+ console.log(f(o, o));
+ }
+ expect: {
+ function f(a, b) {
+ var c = a.p;
+ b.f();
+ return c;
+ }
+ var o = {
+ p: "PASS",
+ f: function() {
+ this.p = "FAIL";
+ }
+ }
+ console.log(f(o, o));
+ }
+ expect_stdout: "PASS"
+}
+
+issue_2364_8: {
+ options = {
+ collapse_vars: true,
+ pure_getters: true,
+ }
+ input: {
+ function f(a, b, c) {
+ var d = a[b.f = function() {
+ return "PASS";
+ }];
+ return c.f(d);
+ }
+ var o = {
+ f: function() {
+ return "FAIL";
+ }
+ };
+ console.log(f({}, o, o));
+ }
+ expect: {
+ function f(a, b, c) {
+ var d = a[b.f = function() {
+ return "PASS";
+ }];
+ return c.f(d);
+ }
+ var o = {
+ f: function() {
+ return "FAIL";
+ }
+ };
+ console.log(f({}, o, o));
+ }
+ expect_stdout: "PASS"
+}
+
+issue_2364_9: {
+ options = {
+ collapse_vars: true,
+ pure_getters: true,
+ }
+ input: {
+ function f(a, b) {
+ var d = a();
+ return b.f(d);
+ }
+ var o = {
+ f: function() {
+ return "FAIL";
+ }
+ };
+ console.log(f(function() {
+ o.f = function() {
+ return "PASS";
+ };
+ }, o));
+ }
+ expect: {
+ function f(a, b) {
+ var d = a();
+ return b.f(d);
+ }
+ var o = {
+ f: function() {
+ return "FAIL";
+ }
+ };
+ console.log(f(function() {
+ o.f = function() {
+ return "PASS";
+ };
+ }, o));
+ }
+ expect_stdout: "PASS"
+}