Skip to content

minifier: var declared with a initializer conditionally is inlined unconditionally #24531

Description

@sapphi-red
function test() {
  if (window.doesntExist) {
    var callback = true
  }
  return () => {
    console.log(callback ? "ng" : "ok")
  };
}
test();
test();

is transformed to

function test() {
	if (window.doesntExist) var callback = !0;
	return () => {
		console.log("ng");
	};
}
test(), test();

. But this changes the behavior.

Originally reported at vitejs/vite#22933

Metadata

Metadata

Assignees

Labels

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions