suppress invalid AST transform in --reduce-test (#4833)
This commit is contained in:
@@ -183,6 +183,24 @@ describe("test/reduce.js", function() {
|
|||||||
"// }",
|
"// }",
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
|
it("Should reduce `for (const ... in ...)` without invalid intermediate AST", function() {
|
||||||
|
if (semver.satisfies(process.version, "<4")) return;
|
||||||
|
var code = [
|
||||||
|
"var a = 0;",
|
||||||
|
"",
|
||||||
|
"for (const b in [ 1, 2, 3 ]) {",
|
||||||
|
" a = +a + 1 - .2;",
|
||||||
|
" console.log(a);",
|
||||||
|
"}",
|
||||||
|
].join("\n");
|
||||||
|
var result = reduce_test(code, {
|
||||||
|
compress: {
|
||||||
|
unsafe_math: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.deepEqual(result.warnings, []);
|
||||||
|
});
|
||||||
it("Should reduce infinite loops with reasonable performance", function() {
|
it("Should reduce infinite loops with reasonable performance", function() {
|
||||||
if (semver.satisfies(process.version, "<=0.10")) return;
|
if (semver.satisfies(process.version, "<=0.10")) return;
|
||||||
this.timeout(120000);
|
this.timeout(120000);
|
||||||
@@ -379,4 +397,21 @@ describe("test/reduce.js", function() {
|
|||||||
"// }",
|
"// }",
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
|
it("Should reduce object with method syntax without invalid intermediate AST", function() {
|
||||||
|
if (semver.satisfies(process.version, "<4")) return;
|
||||||
|
var code = [
|
||||||
|
"console.log({",
|
||||||
|
" f() {",
|
||||||
|
" return 1 - .8;",
|
||||||
|
" },",
|
||||||
|
"}.f());",
|
||||||
|
].join("\n");
|
||||||
|
var result = reduce_test(code, {
|
||||||
|
compress: {
|
||||||
|
unsafe_math: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.deepEqual(result.warnings, []);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -316,10 +316,11 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
var expr;
|
var expr;
|
||||||
switch ((node.start._permute * steps | 0) % 3) {
|
switch ((node.start._permute * steps | 0) % 3) {
|
||||||
case 0:
|
case 0:
|
||||||
if (!(node.init instanceof U.AST_Definitions
|
if (node.init instanceof U.AST_Definitions) {
|
||||||
&& node.init.definitions[0].name instanceof U.AST_Destructured)) {
|
if (node.init instanceof U.AST_Const) break;
|
||||||
expr = node.init;
|
if (node.init.definitions[0].name instanceof U.AST_Destructured) break;
|
||||||
}
|
}
|
||||||
|
expr = node.init;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
expr = node.object;
|
expr = node.object;
|
||||||
@@ -484,23 +485,27 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
CHANGED = true;
|
CHANGED = true;
|
||||||
return newNode;
|
return newNode;
|
||||||
}, function(node, in_list) {
|
}, function(node, in_list) {
|
||||||
if (node instanceof U.AST_Sequence) {
|
if (node instanceof U.AST_Definitions) {
|
||||||
|
// remove empty var statement
|
||||||
|
if (node.definitions.length == 0) return in_list ? List.skip : new U.AST_EmptyStatement({
|
||||||
|
start: {},
|
||||||
|
});
|
||||||
|
} else if (node instanceof U.AST_ObjectMethod) {
|
||||||
|
if (!/Function$/.test(node.value.TYPE)) return new U.AST_ObjectKeyVal({
|
||||||
|
key: node.key,
|
||||||
|
value: node.value,
|
||||||
|
start: {},
|
||||||
|
});
|
||||||
|
} else if (node instanceof U.AST_Sequence) {
|
||||||
// expand single-element sequence
|
// expand single-element sequence
|
||||||
if (node.expressions.length == 1) return node.expressions[0];
|
if (node.expressions.length == 1) return node.expressions[0];
|
||||||
}
|
} else if (node instanceof U.AST_Try) {
|
||||||
else if (node instanceof U.AST_Try) {
|
|
||||||
// expand orphaned try block
|
// expand orphaned try block
|
||||||
if (!node.bcatch && !node.bfinally) return new U.AST_BlockStatement({
|
if (!node.bcatch && !node.bfinally) return new U.AST_BlockStatement({
|
||||||
body: node.body,
|
body: node.body,
|
||||||
start: {},
|
start: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (node instanceof U.AST_Definitions) {
|
|
||||||
// remove empty var statement
|
|
||||||
if (node.definitions.length == 0) return in_list ? List.skip : new U.AST_EmptyStatement({
|
|
||||||
start: {},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var diff_error_message;
|
var diff_error_message;
|
||||||
|
|||||||
Reference in New Issue
Block a user