aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-02-28 19:59:19 +0800
committerGitHub <noreply@github.com>2018-02-28 19:59:19 +0800
commit73e98dcda48be52f2c045038554b2cfe184a9a5a (patch)
treec16dfe8aba269a2ef4dc4adce6e59f786a5d2fad /test/compress
parent36bca6934de494a79a1c1af952653eaaf9c15ed8 (diff)
downloadtracifyjs-73e98dcda48be52f2c045038554b2cfe184a9a5a.tar.gz
tracifyjs-73e98dcda48be52f2c045038554b2cfe184a9a5a.zip
drop `side_effects`-free `return` values (#2965)
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/collapse_vars.js56
1 files changed, 52 insertions, 4 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index d4ab444e..9a6e5a57 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -3124,7 +3124,7 @@ issue_2425_3: {
expect_stdout: "15"
}
-issue_2437: {
+issue_2437_1: {
options = {
collapse_vars: true,
conditionals: true,
@@ -3140,7 +3140,7 @@ issue_2437: {
}
input: {
function foo() {
- bar();
+ return bar();
}
function bar() {
if (xhrDesc) {
@@ -3157,10 +3157,10 @@ issue_2437: {
return result;
}
}
- foo();
+ console.log(foo());
}
expect: {
- !function() {
+ console.log(function() {
if (xhrDesc) {
var result = !!(req = new XMLHttpRequest()).onreadystatechange;
return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
@@ -3169,6 +3169,54 @@ issue_2437: {
var req, detectFunc = function() {};
(req = new XMLHttpRequest()).onreadystatechange = detectFunc;
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
+ return req.onreadystatechange = null, result;
+ }());
+ }
+}
+
+issue_2437_2: {
+ options = {
+ collapse_vars: true,
+ conditionals: true,
+ inline: true,
+ join_vars: true,
+ passes: 2,
+ reduce_funcs: true,
+ reduce_vars: true,
+ side_effects: true,
+ sequences: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function foo() {
+ bar();
+ }
+ function bar() {
+ if (xhrDesc) {
+ var req = new XMLHttpRequest();
+ var result = !!req.onreadystatechange;
+ Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {});
+ return result;
+ } else {
+ var req = new XMLHttpRequest();
+ var detectFunc = function () {};
+ req.onreadystatechange = detectFunc;
+ var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
+ req.onreadystatechange = null;
+ return result;
+ }
+ }
+ foo();
+ }
+ expect: {
+ !function() {
+ if (xhrDesc)
+ return (req = new XMLHttpRequest()).onreadystatechange,
+ Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {});
+ var req;
+ (req = new XMLHttpRequest).onreadystatechange = function(){},
+ req[SYMBOL_FAKE_ONREADYSTATECHANGE_1],
req.onreadystatechange = null;
}();
}