aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-05 13:09:27 +0800
committerGitHub <noreply@github.com>2017-03-05 13:09:27 +0800
commitb33e7f88e60f886ee3403c82ac2e3fb40caa698f (patch)
tree76d221f44841840055a1187baca0bb3d5c5af009 /test/compress
parent1f0333e9f146311e0e412fbd0783c0e1e63c7802 (diff)
downloadtracifyjs-b33e7f88e60f886ee3403c82ac2e3fb40caa698f.tar.gz
tracifyjs-b33e7f88e60f886ee3403c82ac2e3fb40caa698f.zip
improve `unsafe` on undefined (#1548)
`unsafe` turns undefined keyword into a variable of the same name if found, but that interferes with other related optimisations. Keep track of such transformations to ensure zero information loss in the process.
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/issue-1443.js16
-rw-r--r--test/compress/sequences.js33
2 files changed, 37 insertions, 12 deletions
diff --git a/test/compress/issue-1443.js b/test/compress/issue-1443.js
index a2565872..304a71ac 100644
--- a/test/compress/issue-1443.js
+++ b/test/compress/issue-1443.js
@@ -2,6 +2,7 @@
unsafe_undefined: {
options = {
+ conditionals: true,
if_return: true,
unsafe: true
}
@@ -19,12 +20,7 @@ unsafe_undefined: {
expect: {
function f(n) {
return function() {
- if (a)
- return b;
- if (c)
- return d;
- else
- return n;
+ return a ? b : c ? d : n;
};
}
}
@@ -32,6 +28,7 @@ unsafe_undefined: {
keep_fnames: {
options = {
+ conditionals: true,
if_return: true,
unsafe: true
}
@@ -57,12 +54,7 @@ keep_fnames: {
function n(n) {
return n * n;
}
- if (a)
- return b;
- if (c)
- return d;
- else
- return r;
+ return a ? b : c ? d : r;
};
}
}
diff --git a/test/compress/sequences.js b/test/compress/sequences.js
index 7bb274cb..41cfc726 100644
--- a/test/compress/sequences.js
+++ b/test/compress/sequences.js
@@ -251,3 +251,36 @@ iife: {
function d() {}(), function e() {}(), function f() {}(), function g() {}();
}
}
+
+unsafe_undefined: {
+ options = {
+ conditionals: true,
+ if_return: true,
+ sequences: true,
+ side_effects: true,
+ unsafe: true,
+ }
+ input: {
+ function f(undefined) {
+ if (a)
+ return b;
+ if (c)
+ return d;
+ }
+ function g(undefined) {
+ if (a)
+ return b;
+ if (c)
+ return d;
+ e();
+ }
+ }
+ expect: {
+ function f(undefined) {
+ return a ? b : c ? d : undefined;
+ }
+ function g(undefined) {
+ return a ? b : c ? d : void e();
+ }
+ }
+}