Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minifier: dce + var hosting edge cases #7209

Open
underfin opened this issue Nov 8, 2024 · 6 comments
Open

minifier: dce + var hosting edge cases #7209

underfin opened this issue Nov 8, 2024 · 6 comments
Assignees
Labels
A-minifier Area - Minifier C-bug Category - Bug

Comments

@underfin
Copy link
Contributor

underfin commented Nov 8, 2024

Input

if (false) {
	for (var a; unknownGlobal && true; unknownGlobal && true) var b;
} else {
	console.log(a, b);
}

if (((() => console.log('effect'))(), true)) {
} else {
	var c = 1;
	for (var c; unknownGlobal && true; unknownGlobal && true) var d;
}
console.log(c, d);

Output

console.log(a, b);
console.log(c, d);

Expected

var b, a; {
	console.log(a, b);
}

var c, d; if (((() => console.log('effect'))(), true)) ;
console.log(c, d);

The a,b,c,d need to hosted, the ((() => console.log('effect'))() need to preserve.

Found the case at https://github.com/rollup/rollup/blob/master/test/form/samples/hoisted-vars-in-dead-branches/main.js

@underfin underfin added the C-bug Category - Bug label Nov 8, 2024
@Boshen Boshen self-assigned this Nov 8, 2024
@7086cmd 7086cmd self-assigned this Nov 9, 2024
@7086cmd 7086cmd added the A-minifier Area - Minifier label Nov 9, 2024
@7086cmd
Copy link
Contributor

7086cmd commented Nov 9, 2024

Is the swc's result better than the expected?

var d, c;
console.log(void 0, void 0), console.log('effect'), console.log(c, d);
Closure Compiler's
var d,c,b,a;console.log(a,b);(()=>console.log("effect"))();console.log(c,d);

@Boshen
Copy link
Member

Boshen commented Nov 11, 2024

I need to spend some time rewriting this part of the code, it's a bit more involved.

@Boshen Boshen changed the title remove dead branch transfomer need to hosited variables and keep the side effect minifier: dce + var hosting edge cases Nov 11, 2024
@underfin

This comment was marked as off-topic.

@underfin

This comment was marked as off-topic.

@IWANABETHATGUY

This comment was marked as off-topic.

@IWANABETHATGUY

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-minifier Area - Minifier C-bug Category - Bug
Projects
None yet
Development

No branches or pull requests

4 participants