Skip to content

Commit

Permalink
improve --reduce-test (#5763)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Dec 13, 2022
1 parent 797184f commit f2b6f1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
12 changes: 3 additions & 9 deletions test/input/reduce/unsafe_math.reduced.js
@@ -1,16 +1,10 @@
// (beautified)
var b = 0;

var expr2 = (0 - 1 - .1 - .1).toString();

for (var key2 in expr2) {
--b;
}

console.log(b);
// output: -19
console.log(expr2);
// output: -1.2000000000000002
//
// minify: -4
// minify: -1.2
//
// options: {
// "compress": {
Expand Down
4 changes: 2 additions & 2 deletions test/mocha/reduce.js
Expand Up @@ -236,9 +236,9 @@ describe("test/reduce.js", function() {
});
it("Should report trailing whitespace difference in stringified format", function() {
var code = [
"for (var a in (1 - .8).toString()) {",
"[].forEach.call((1 - .8).toString(), function() {",
" console.log();",
"}",
"});",
].join("\n");
var result = reduce_test(code, {
compress: {
Expand Down
20 changes: 11 additions & 9 deletions test/reduce.js
Expand Up @@ -193,7 +193,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
}
else if (node instanceof U.AST_BlockStatement) {
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) {
node.start._permute++;
CHANGED = true;
Expand Down Expand Up @@ -335,19 +335,21 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
}
else if (node instanceof U.AST_ForEnumeration) {
var expr;
switch ((node.start._permute * steps | 0) % 3) {
switch ((node.start._permute * steps | 0) % 4) {
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;
expr = node.object;
break;
case 1:
expr = node.object;
expr = wrap_with_console_log(node.object);
break;
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;
}
node.start._permute += step;
Expand Down

0 comments on commit f2b6f1d

Please sign in to comment.