Skip to content

Commit

Permalink
fix corner case in inline (#3401)
Browse files Browse the repository at this point in the history
fixes #3400
  • Loading branch information
alexlamsl committed May 9, 2019
1 parent 6a30e1d commit 5476cb8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
1 change: 0 additions & 1 deletion lib/compress.js
Expand Up @@ -6102,7 +6102,6 @@ merge(Compressor.prototype, {
}));
} else {
value = fixed.optimize(compressor);
if (value === fixed) value = fixed.clone(true);
}
def.replaced++;
return value;
Expand Down
12 changes: 6 additions & 6 deletions test/compress/collapse_vars.js
Expand Up @@ -3497,10 +3497,10 @@ issue_2437_1: {
return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
result;
}
var req, detectFunc = function(){};
(req = new XMLHttpRequest()).onreadystatechange = detectFunc;
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
return req.onreadystatechange = null, result;
var req = new XMLHttpRequest(), detectFunc = function(){};
return req.onreadystatechange = detectFunc,
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
req.onreadystatechange = null, result;
}());
}
}
Expand Down Expand Up @@ -3545,8 +3545,8 @@ issue_2437_2: {
if (xhrDesc)
return (req = new XMLHttpRequest()).onreadystatechange,
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {});
var req;
(req = new XMLHttpRequest).onreadystatechange = function(){},
var req = new XMLHttpRequest();
req.onreadystatechange = function(){},
req[SYMBOL_FAKE_ONREADYSTATECHANGE_1],
req.onreadystatechange = null;
}();
Expand Down
2 changes: 2 additions & 0 deletions test/compress/drop-unused.js
Expand Up @@ -797,6 +797,7 @@ assign_chain: {
issue_1583: {
options = {
keep_fargs: true,
passes: 2,
reduce_funcs: true,
reduce_vars: true,
unused: true,
Expand Down Expand Up @@ -1144,6 +1145,7 @@ var_catch_toplevel: {
options = {
conditionals: true,
negate_iife: true,
passes: 2,
reduce_funcs: true,
reduce_vars: true,
side_effects: true,
Expand Down
56 changes: 52 additions & 4 deletions test/compress/functions.js
Expand Up @@ -2860,10 +2860,10 @@ issue_2437: {
result;
}
function detectFunc() {}
var req;
(req = new XMLHttpRequest()).onreadystatechange = detectFunc;
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
return req.onreadystatechange = null, result;
var req = new XMLHttpRequest();
return req.onreadystatechange = detectFunc,
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
req.onreadystatechange = null, result;
}());
}
}
Expand Down Expand Up @@ -3065,3 +3065,51 @@ class_iife: {
}
expect_stdout: "PASS"
}

issue_3400: {
options = {
collapse_vars: true,
inline: true,
reduce_funcs: true,
reduce_vars: true,
unused: true,
}
input: {
(function(f) {
console.log(f()()[0].p);
})(function() {
function g() {
function h(u) {
var o = {
p: u
};
return console.log(o[g]), o;
}
function e() {
return [ 42 ].map(function(v) {
return h(v);
});
}
return e();
}
return g;
});
}
expect: {
void console.log(function g() {
function e() {
return [42].map(function(v) {
return o = {
p: v
}, console.log(o[g]) , o;
var o;
});
}
return e();
}()[0].p);
}
expect_stdout: [
"undefined",
"42",
]
}

0 comments on commit 5476cb8

Please sign in to comment.