Skip to content

Commit

Permalink
tweak test & warnings (#5123)
Browse files Browse the repository at this point in the history
closes #5116
closes #5117
closes #5122
  • Loading branch information
alexlamsl authored Sep 6, 2021
1 parent c3aef23 commit 4b88dfb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
15 changes: 6 additions & 9 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3716,12 +3716,8 @@ merge(Compressor.prototype, {
}

function extract_declarations_from_unreachable_code(compressor, stat, target) {
if (!(stat instanceof AST_DefClass
|| stat instanceof AST_Definitions
|| stat instanceof AST_LambdaDefinition)) {
AST_Node.warn("Dropping unreachable code [{file}:{line},{col}]", stat.start);
}
var block;
var dropped = false;
stat.walk(new TreeWalker(function(node, descend) {
if (node instanceof AST_DefClass) {
node.extends = null;
Expand Down Expand Up @@ -3750,16 +3746,17 @@ merge(Compressor.prototype, {
block = [];
descend();
if (block.required) {
target.push(make_node(AST_BlockStatement, stat, {
body: block
}));
target.push(make_node(AST_BlockStatement, stat, { body: block }));
} else if (block.length) {
[].push.apply(target, block);
}
block = save;
return true;
}
if (!(node instanceof AST_LoopControl)) dropped = true;
}));
if (dropped) AST_Node.warn("Dropping unreachable code [{file}:{line},{col}]", stat.start);

function push(node) {
if (block) {
block.push(node);
Expand Down Expand Up @@ -6709,7 +6706,7 @@ merge(Compressor.prototype, {
if (tail.length == 0) break;
if (tail.length == duplicated) {
[].unshift.apply(side_effects, tail.map(function(def) {
AST_Node.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name));
AST_Node.info("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name));
var sym = def.name.definition();
var ref = make_node(AST_SymbolRef, def.name, def.name);
sym.references.push(ref);
Expand Down
63 changes: 34 additions & 29 deletions test/mocha/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,35 +282,40 @@ describe("test/reduce.js", function() {
});
if (result.error) throw result.error;
assert.deepEqual(result.warnings, []);
assert.strictEqual(result.code.replace(/function \(/g, "function("), (semver.satisfies(process.version, "<=0.10") ? [
"// Can't reproduce test failure",
"// minify options: {",
'// "compress": false,',
'// "mangle": false,',
'// "output": {',
'// "beautify": true',
"// }",
"// }",
] : [
[
"try{",
"null[function(){}]",
"}catch(e){",
"console.log(e)",
"}",
].join(""),
"// output: TypeError: Cannot read property 'function(){}' of null",
"// ",
"// minify: TypeError: Cannot read property 'function() {}' of null",
"// ",
"// options: {",
'// "compress": false,',
'// "mangle": false,',
'// "output": {',
'// "beautify": true',
"// }",
"// }",
]).join("\n"));
if (semver.satisfies(process.version, "<=0.10")) {
assert.strictEqual(result.code, [
"// Can't reproduce test failure",
"// minify options: {",
'// "compress": false,',
'// "mangle": false,',
'// "output": {',
'// "beautify": true',
"// }",
"// }",
].join("\n"));
} else {
var message = result.code.split(/\n/, 3)[1].slice("// output: ".length);
assert.strictEqual(result.code, [
[
"try{",
"null[function(){}]",
"}catch(e){",
"console.log(e)",
"}",
].join(""),
"// output: " + message,
"// ",
"// minify: " + message.replace("(){}", "() {}"),
"// ",
"// options: {",
'// "compress": false,',
'// "mangle": false,',
'// "output": {',
'// "beautify": true',
"// }",
"// }",
].join("\n"));
}
});
it("Should maintain block-scope for const/let", function() {
if (semver.satisfies(process.version, "<4")) return;
Expand Down

0 comments on commit 4b88dfb

Please sign in to comment.