"// }",
].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() {
if (semver.satisfies(process.version, "<=0.10")) return;
this.timeout(120000);
"// }",
].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, []);
+ });
});
var expr;
switch ((node.start._permute * steps | 0) % 3) {
case 0:
- if (!(node.init instanceof U.AST_Definitions
- && node.init.definitions[0].name instanceof U.AST_Destructured)) {
- expr = node.init;
+ 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;
CHANGED = true;
return newNode;
}, 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
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
if (!node.bcatch && !node.bfinally) return new U.AST_BlockStatement({
body: node.body,
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;