improve --reduce-test (#5763)

This commit is contained in:
Alex Lam S.L
2022-12-13 04:07:15 +02:00
committed by GitHub
parent 797184f587
commit f2b6f1def0
3 changed files with 17 additions and 21 deletions

View File

@@ -1,16 +1,10 @@
// (beautified) // (beautified)
var b = 0;
var expr2 = (0 - 1 - .1 - .1).toString(); var expr2 = (0 - 1 - .1 - .1).toString();
for (var key2 in expr2) { console.log(expr2);
--b; // output: -1.2000000000000002
}
console.log(b);
// output: -19
// //
// minify: -4 // minify: -1.2
// //
// options: { // options: {
// "compress": { // "compress": {

View File

@@ -236,9 +236,9 @@ describe("test/reduce.js", function() {
}); });
it("Should report trailing whitespace difference in stringified format", function() { it("Should report trailing whitespace difference in stringified format", function() {
var code = [ var code = [
"for (var a in (1 - .8).toString()) {", "[].forEach.call((1 - .8).toString(), function() {",
" console.log();", " console.log();",
"}", "});",
].join("\n"); ].join("\n");
var result = reduce_test(code, { var result = reduce_test(code, {
compress: { compress: {

View File

@@ -193,7 +193,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
} }
else if (node instanceof U.AST_BlockStatement) { else if (node instanceof U.AST_BlockStatement) {
if (in_list && node.body.filter(function(node) { if (in_list && node.body.filter(function(node) {
return node instanceof U.AST_Const; return node instanceof U.AST_Const || node instanceof U.AST_Let;
}).length == 0) { }).length == 0) {
node.start._permute++; node.start._permute++;
CHANGED = true; CHANGED = true;
@@ -335,19 +335,21 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
} }
else if (node instanceof U.AST_ForEnumeration) { else if (node instanceof U.AST_ForEnumeration) {
var expr; var expr;
switch ((node.start._permute * steps | 0) % 3) { switch ((node.start._permute * steps | 0) % 4) {
case 0: case 0:
if (node.init instanceof U.AST_Definitions) {
if (node.init instanceof U.AST_Const) break;
if (node.init.definitions[0].name instanceof U.AST_Destructured) break;
}
expr = node.init;
break;
case 1:
expr = node.object; expr = node.object;
break; break;
case 1:
expr = wrap_with_console_log(node.object);
break;
case 2: case 2:
if (!has_loopcontrol(node.body, node, parent)) expr = node.body; if (has_loopcontrol(node.body, node, parent)) break;
expr = node.body;
break;
case 3:
if (!(node.init instanceof U.AST_Var)) break;
if (node.init.definitions[0].name instanceof U.AST_Destructured) break;
expr = node.init;
break; break;
} }
node.start._permute += step; node.start._permute += step;