fix corner case in merge_vars (#5452)

fixes #5451
This commit is contained in:
Alex Lam S.L
2022-05-17 19:41:05 +01:00
committed by GitHub
parent cb6dd34b98
commit 63f16e4616
4 changed files with 33 additions and 8 deletions

View File

@@ -6183,8 +6183,11 @@ Compressor.prototype.compress = function(node) {
return true; return true;
} }
if (node instanceof AST_Scope) { if (node instanceof AST_Scope) {
var in_iife = false;
if (node instanceof AST_LambdaExpression && !node.name) {
var parent = tw.parent(); var parent = tw.parent();
var in_iife = parent && parent.TYPE == "Call" && parent.expression === node; in_iife = parent && parent.TYPE == "Call" && parent.expression === node;
}
if (!in_iife) { if (!in_iife) {
push(); push();
segment.block = node; segment.block = node;

View File

@@ -184,12 +184,12 @@ merge_vars_2: {
expect: { expect: {
var a = 0; var a = 0;
1 && --a, 1 && --a,
a = function f() { b = function f() {
const c = a && f; const c = a && f;
c.var += 0; c.var += 0;
}(), }(),
void console.log(a); void console.log(b);
var a; var b;
} }
expect_stdout: "undefined" expect_stdout: "undefined"
} }

View File

@@ -237,12 +237,12 @@ merge_vars_2: {
"use strict"; "use strict";
var a = 0; var a = 0;
1 && --a, 1 && --a,
a = function f() { b = function f() {
let c = a && f; let c = a && f;
c.var += 0; c.var += 0;
}(), }(),
void console.log(a); void console.log(b);
var a; var b;
} }
expect_stdout: "undefined" expect_stdout: "undefined"
node_version: ">=4" node_version: ">=4"

View File

@@ -3732,3 +3732,25 @@ issue_5420: {
} }
expect_stdout: "PASS" expect_stdout: "PASS"
} }
issue_5451: {
options = {
merge_vars: true,
toplevel: true,
}
input: {
A = 1;
var a = 1, b;
console.log(function f() {
return a-- && f(b = A, b);
}());
}
expect: {
A = 1;
var a = 1, b;
console.log(function f() {
return a-- && f(b = A, b);
}());
}
expect_stdout: "0"
}