Skip to content

Commit

Permalink
fix corner case in inline (#5343)
Browse files Browse the repository at this point in the history
fixes #5342
  • Loading branch information
alexlamsl committed Feb 5, 2022
1 parent d338e45 commit 6fb7de7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 20 deletions.
16 changes: 3 additions & 13 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -9469,16 +9469,12 @@ Compressor.prototype.compress = function(node) {
if (self.bfinally) {
body.push(make_node(AST_BlockStatement, self.bfinally, self.bfinally).optimize(compressor));
}
return make_node(AST_BlockStatement, self, {
body: body
}).optimize(compressor);
return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor);
}
if (self.bfinally && has_declarations_only(self.bfinally)) {
var body = make_node(AST_BlockStatement, self.bfinally, self.bfinally).optimize(compressor);
body = self.body.concat(body);
if (!self.bcatch) return make_node(AST_BlockStatement, self, {
body: body
}).optimize(compressor);
if (!self.bcatch) return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor);
self.body = body;
self.bfinally = null;
}
Expand Down Expand Up @@ -13174,6 +13170,7 @@ Compressor.prototype.compress = function(node) {
if (fn.contains_this()) return;
if (!scope) scope = find_scope(compressor);
var defined = new Dictionary();
defined.set("NaN", true);
while (!(scope instanceof AST_Scope)) {
scope.variables.each(function(def) {
defined.set(def.name, true);
Expand Down Expand Up @@ -13263,13 +13260,6 @@ Compressor.prototype.compress = function(node) {
if (sym instanceof AST_SymbolCatch) return;
body.push(make_node(AST_SimpleStatement, sym, { body: init_ref(compressor, flatten_var(sym)) }));
});
if (fn.variables.has("NaN")) scope.transform(new TreeTransformer(function(node) {
if (node instanceof AST_NaN) return make_node(AST_Binary, node, {
operator: "/",
left: make_node(AST_Number, node, { value: 0 }),
right: make_node(AST_Number, node, { value: 0 }),
});
}));
var defs = Object.create(null), syms = new Dictionary();
if (simple_argnames && all(call.args, function(arg) {
return !(arg instanceof AST_Spread);
Expand Down
75 changes: 75 additions & 0 deletions test/compress/arrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,78 @@ issue_5251: {
expect_stdout: true
node_version: ">=4"
}

issue_5342_1: {
options = {
dead_code: true,
inline: true,
toplevel: true,
unused: true,
}
input: {
for (var a in 0) {
(() => {
while (1);
})(new function(NaN) {
a.p;
}());
}
console.log(function() {
return b;
try {
b;
} catch (e) {
var b;
}
}());
}
expect: {
for (var a in 0) {
(function(NaN) {
a.p;
})();
while (1);
}
console.log(b);
var b;
}
expect_stdout: "undefined"
node_version: ">=4"
}

issue_5342_2: {
rename = true
options = {
dead_code: true,
inline: true,
toplevel: true,
unused: true,
}
input: {
for (var a in 0) {
(() => {
while (1);
})(new function(NaN) {
a.p;
}());
}
console.log(function() {
return b;
try {
b;
} catch (e) {
var b;
}
}());
}
expect: {
for (var a in 0) {
a.p;
while (1);
}
console.log(c);
var c;
}
expect_stdout: "undefined"
node_version: ">=4"
}
13 changes: 6 additions & 7 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1713,16 +1713,14 @@ issue_2620_5: {
}
expect: {
var c = "FAIL";
(function() {
var a = 0/0;
var NaN = void 0;
!function(a, NaN) {
switch (a) {
case a:
break;
case c = "PASS", NaN:
break;
}
})();
}(NaN);
console.log(c);
}
expect_stdout: "PASS"
Expand Down Expand Up @@ -7635,9 +7633,10 @@ issue_5237: {
}
expect: {
function f() {
while (console.log(0/0));
var NaN = console && console.log(NaN);
return;
while (console.log(NaN));
(function() {
var NaN = console && console.log(NaN);
})();
}
f();
}
Expand Down

0 comments on commit 6fb7de7

Please sign in to comment.