Skip to content

Commit f2b6f1d

Browse files
authored
improve --reduce-test (#5763)
1 parent 797184f commit f2b6f1d

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

test/input/reduce/unsafe_math.reduced.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
// (beautified)
2-
var b = 0;
3-
42
var expr2 = (0 - 1 - .1 - .1).toString();
53

6-
for (var key2 in expr2) {
7-
--b;
8-
}
9-
10-
console.log(b);
11-
// output: -19
4+
console.log(expr2);
5+
// output: -1.2000000000000002
126
//
13-
// minify: -4
7+
// minify: -1.2
148
//
159
// options: {
1610
// "compress": {

test/mocha/reduce.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ describe("test/reduce.js", function() {
236236
});
237237
it("Should report trailing whitespace difference in stringified format", function() {
238238
var code = [
239-
"for (var a in (1 - .8).toString()) {",
239+
"[].forEach.call((1 - .8).toString(), function() {",
240240
" console.log();",
241-
"}",
241+
"});",
242242
].join("\n");
243243
var result = reduce_test(code, {
244244
compress: {

test/reduce.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
193193
}
194194
else if (node instanceof U.AST_BlockStatement) {
195195
if (in_list && node.body.filter(function(node) {
196-
return node instanceof U.AST_Const;
196+
return node instanceof U.AST_Const || node instanceof U.AST_Let;
197197
}).length == 0) {
198198
node.start._permute++;
199199
CHANGED = true;
@@ -335,19 +335,21 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
335335
}
336336
else if (node instanceof U.AST_ForEnumeration) {
337337
var expr;
338-
switch ((node.start._permute * steps | 0) % 3) {
338+
switch ((node.start._permute * steps | 0) % 4) {
339339
case 0:
340-
if (node.init instanceof U.AST_Definitions) {
341-
if (node.init instanceof U.AST_Const) break;
342-
if (node.init.definitions[0].name instanceof U.AST_Destructured) break;
343-
}
344-
expr = node.init;
340+
expr = node.object;
345341
break;
346342
case 1:
347-
expr = node.object;
343+
expr = wrap_with_console_log(node.object);
348344
break;
349345
case 2:
350-
if (!has_loopcontrol(node.body, node, parent)) expr = node.body;
346+
if (has_loopcontrol(node.body, node, parent)) break;
347+
expr = node.body;
348+
break;
349+
case 3:
350+
if (!(node.init instanceof U.AST_Var)) break;
351+
if (node.init.definitions[0].name instanceof U.AST_Destructured) break;
352+
expr = node.init;
351353
break;
352354
}
353355
node.start._permute += step;

0 commit comments

Comments
 (0)