improve handling of non-trivial assignment values (#5227)
This commit is contained in:
@@ -489,7 +489,7 @@ logical_assignments: {
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
logical_collapse_vars: {
|
||||
logical_collapse_vars_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
@@ -509,6 +509,27 @@ logical_collapse_vars: {
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
logical_collapse_vars_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
(function(b) {
|
||||
b ||= (a = "FAIL", {});
|
||||
return b;
|
||||
})(console).log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
(function(b) {
|
||||
return b ||= (a = "FAIL", {});
|
||||
})(console).log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
logical_reduce_vars: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
|
||||
@@ -346,9 +346,7 @@ collapse_vars_if: {
|
||||
return "x" != "Bar" + x / 4 ? g9 : g5;
|
||||
}
|
||||
function f3(x) {
|
||||
if (x)
|
||||
return 1;
|
||||
return 2;
|
||||
return x ? 1 : 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1912,6 +1910,42 @@ collapse_vars_regexp: {
|
||||
]
|
||||
}
|
||||
|
||||
collapse_arg_sequence: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(a) {
|
||||
a("foo");
|
||||
})((console.log("bar"), console.log));
|
||||
}
|
||||
expect: {
|
||||
(function(a) {
|
||||
(0, console.log)("foo");
|
||||
})(console.log("bar"));
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
}
|
||||
|
||||
collapse_for_init: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
for (var a = (Math, console), b = a.log("PASS"); b;);
|
||||
}
|
||||
expect: {
|
||||
Math;
|
||||
for (var a, b = console.log("PASS"); b;);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_1537: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -2667,6 +2701,24 @@ chained_4: {
|
||||
expect_stdout: "foo undefined"
|
||||
}
|
||||
|
||||
chained_5: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
var a = (console, console.log(a));
|
||||
a && ++a;
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
console;
|
||||
var a;
|
||||
(a = console.log(a)) && ++a;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
boolean_binary_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -2906,6 +2958,43 @@ compound_assignment_2: {
|
||||
expect_stdout: "4"
|
||||
}
|
||||
|
||||
compound_assignment_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = 1;
|
||||
a += (console.log("PASS"), 2);
|
||||
a.p;
|
||||
}
|
||||
expect: {
|
||||
var a = 1;
|
||||
(a += (console.log("PASS"), 2)).p;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
compound_assignment_4: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
A = "PASS";
|
||||
var a = "";
|
||||
a += (a = "FAIL", A);
|
||||
a.p;
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
A = "PASS";
|
||||
var a = "";
|
||||
(a += (a = "FAIL", A)).p;
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_2187_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -3030,10 +3119,10 @@ issue_2203_2: {
|
||||
a: "FAIL",
|
||||
b: function() {
|
||||
return function(c) {
|
||||
return (String, (Object, function() {
|
||||
return (Object, function() {
|
||||
return this;
|
||||
}())).a;
|
||||
}();
|
||||
}()).a;
|
||||
}(String);
|
||||
}
|
||||
}.b());
|
||||
}
|
||||
@@ -3764,17 +3853,17 @@ issue_2437_1: {
|
||||
console.log(foo());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
if (xhrDesc) {
|
||||
var result = !!(req = new XMLHttpRequest()).onreadystatechange;
|
||||
return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
|
||||
result;
|
||||
}
|
||||
var req = new XMLHttpRequest(), detectFunc = function(){};
|
||||
return req.onreadystatechange = detectFunc,
|
||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
|
||||
req.onreadystatechange = null, result;
|
||||
}());
|
||||
var req, detectFunc, result;
|
||||
console.log((
|
||||
xhrDesc ? (result = !!(req = new XMLHttpRequest).onreadystatechange,
|
||||
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc||{})
|
||||
) : (
|
||||
(req = new XMLHttpRequest).onreadystatechange = detectFunc = function(){},
|
||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
|
||||
req.onreadystatechange = null
|
||||
),
|
||||
result
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3815,15 +3904,15 @@ issue_2437_2: {
|
||||
foo();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
if (xhrDesc)
|
||||
return (req = new XMLHttpRequest()).onreadystatechange,
|
||||
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {});
|
||||
var req = new XMLHttpRequest();
|
||||
req.onreadystatechange = function(){},
|
||||
var req;
|
||||
xhrDesc ? (
|
||||
(req = new XMLHttpRequest).onreadystatechange,
|
||||
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {})
|
||||
) : (
|
||||
(req = new XMLHttpRequest).onreadystatechange = function(){},
|
||||
req[SYMBOL_FAKE_ONREADYSTATECHANGE_1],
|
||||
req.onreadystatechange = null;
|
||||
}();
|
||||
req.onreadystatechange = null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6445,7 +6534,8 @@ assign_undeclared: {
|
||||
console.log(typeof B);
|
||||
}
|
||||
expect: {
|
||||
B = new (console.log(42), function() {})();
|
||||
console.log(42);
|
||||
B = new function() {}();
|
||||
console.log(typeof B);
|
||||
}
|
||||
expect_stdout: [
|
||||
@@ -9141,9 +9231,7 @@ issue_4908: {
|
||||
console.log(d[1]);
|
||||
}
|
||||
expect: {
|
||||
var a = 0, b;
|
||||
console || a++;
|
||||
var c = a, d = [ (d = a) && d, d += 42 ];
|
||||
var a = 0, b, c = (console || a++, a), d = [ (d = a) && d, d += 42 ];
|
||||
console.log(d[1]);
|
||||
}
|
||||
expect_stdout: "42"
|
||||
|
||||
@@ -158,6 +158,28 @@ process_boolean_returns: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
collapse_arg_sequence: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(a = (console.log("bar"), console.log)) {
|
||||
a("foo");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function(a = console.log("bar")) {
|
||||
(0, console.log)("foo");
|
||||
})();
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
collapse_value_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
|
||||
@@ -395,7 +395,8 @@ funarg_unused_6_keep_fargs: {
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
var {} = (console, 42);
|
||||
console;
|
||||
var {} = 42;
|
||||
})();
|
||||
console.log(typeof a);
|
||||
}
|
||||
|
||||
@@ -1728,7 +1728,8 @@ issue_2768: {
|
||||
}
|
||||
expect: {
|
||||
var a = "FAIL";
|
||||
var c = (d = a, void (d && (a = "PASS")));
|
||||
d = a;
|
||||
var c = void (d && (a = "PASS"));
|
||||
var d;
|
||||
console.log(a, typeof c);
|
||||
}
|
||||
@@ -2382,7 +2383,8 @@ issue_3664: {
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
var a, b = (a = (a = [ b && console.log("FAIL") ]).p = 0, 0);
|
||||
a = (a = [ b && console.log("FAIL") ]).p = 0;
|
||||
var a, b = 0;
|
||||
return "PASS";
|
||||
}());
|
||||
}
|
||||
@@ -2551,10 +2553,9 @@ issue_3899: {
|
||||
console.log(typeof a);
|
||||
}
|
||||
expect: {
|
||||
function a() {
|
||||
console.log(typeof function() {
|
||||
return 2;
|
||||
}
|
||||
console.log(typeof a);
|
||||
});
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ issue_4664: {
|
||||
expect: {
|
||||
(function f() {
|
||||
new function(a) {
|
||||
console.log(typeof f, a, typeof this);
|
||||
}((A = 0, 2 ** 30));
|
||||
console.log(typeof f, 2 ** 30, typeof this);
|
||||
}(A = 0);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "function 1073741824 object"
|
||||
|
||||
@@ -3039,18 +3039,17 @@ issue_2437: {
|
||||
console.log(foo());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
if (xhrDesc) {
|
||||
var result = !!(req = new XMLHttpRequest()).onreadystatechange;
|
||||
return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
|
||||
result;
|
||||
}
|
||||
function detectFunc() {}
|
||||
var req = new XMLHttpRequest();
|
||||
return req.onreadystatechange = detectFunc,
|
||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
|
||||
req.onreadystatechange = null, result;
|
||||
}());
|
||||
var req, detectFunc, result;
|
||||
console.log((
|
||||
xhrDesc ? (
|
||||
result = !!(req = new XMLHttpRequest).onreadystatechange,
|
||||
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {})
|
||||
) : (
|
||||
(req = new XMLHttpRequest).onreadystatechange = detectFunc = function(){},
|
||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,req.onreadystatechange = null
|
||||
),
|
||||
result
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3826,16 +3825,14 @@ inlined_single_use: {
|
||||
}
|
||||
expect: {
|
||||
console.log(function(f) {
|
||||
var a = function() {
|
||||
a = function() {
|
||||
A;
|
||||
};
|
||||
var b = function() {
|
||||
},
|
||||
b = function() {
|
||||
a(B);
|
||||
};
|
||||
(function() {
|
||||
b;
|
||||
});
|
||||
return;
|
||||
},
|
||||
void 0;
|
||||
var a, b;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
@@ -5290,6 +5287,42 @@ direct_inline_catch_redefined: {
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
statement_var_inline: {
|
||||
options = {
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
(function() {
|
||||
var a = {};
|
||||
function g() {
|
||||
a.p;
|
||||
}
|
||||
g(console.log("PASS"));
|
||||
var b = function h(c) {
|
||||
c && c.q;
|
||||
}();
|
||||
})();
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
var c, a = {};
|
||||
function g() {
|
||||
a.p;
|
||||
}
|
||||
g(console.log("PASS"));
|
||||
c && c.q;
|
||||
return;
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_4171_1: {
|
||||
options = {
|
||||
functions: true,
|
||||
|
||||
@@ -282,7 +282,7 @@ issue_4736: {
|
||||
(function() {
|
||||
(function() {
|
||||
0,
|
||||
console.log(1073741824);
|
||||
console.log(1 << 30);
|
||||
})();
|
||||
})();
|
||||
}
|
||||
@@ -336,7 +336,7 @@ issue_4859: {
|
||||
}
|
||||
expect: {
|
||||
(function f(a) {
|
||||
console.log(Infinity);
|
||||
console.log(2 + 1 / 0);
|
||||
return f;
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -1282,10 +1282,7 @@ assign_sequence_var: {
|
||||
console.log(a, b, c);
|
||||
}
|
||||
expect: {
|
||||
var a = 0, b = 1;
|
||||
console.log(a),
|
||||
a++;
|
||||
var b = 2, c = 3;
|
||||
var a = 0, b = 1, c = (console.log(a), a++, b = 2, 3);
|
||||
console.log(a, b, c);
|
||||
}
|
||||
expect_stdout: [
|
||||
|
||||
@@ -181,10 +181,10 @@ issue_2203_2: {
|
||||
a: "FAIL",
|
||||
b: function() {
|
||||
return function() {
|
||||
return (String, (Object, function() {
|
||||
return (Object, function() {
|
||||
return this;
|
||||
}())).a;
|
||||
}();
|
||||
}()).a;
|
||||
}(String);
|
||||
}
|
||||
}.b());
|
||||
}
|
||||
|
||||
@@ -910,9 +910,7 @@ hoist_decl: {
|
||||
var d;
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
w();
|
||||
var b = x(), c, d;
|
||||
var a, b = (w(), x()), c, d;
|
||||
for (y(); 0;) z();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user