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

[Compressor|RemoveDeadCode]: Wrong simplified expression in the tagged template #4341

Closed
hyf0 opened this issue Jul 18, 2024 · 1 comment · Fixed by #4842 or #5717
Closed

[Compressor|RemoveDeadCode]: Wrong simplified expression in the tagged template #4341

hyf0 opened this issue Jul 18, 2024 · 1 comment · Fixed by #4842 or #5717
Assignees
Labels
A-minifier Area - Minifier C-bug Category - Bug

Comments

@hyf0
Copy link
Contributor

hyf0 commented Jul 18, 2024

For input

let o = {
	f() {
		assert.ok(this !== o);
	}
};
(1, o.f)();
(1, o.f)``;

(true && o.f)();
(true && o.f)``;

(true ? o.f : false)();
(true ? o.f : false)``;

Esbuild's output

let o={f(){assert.ok(this!==o)}};(0,o.f)(),(0,o.f)``,(0,o.f)(),(0,o.f)``,(0,o.f)(),(0,o.f)``;

https://esbuild.github.io/try/#dAAwLjIzLjAALS1taW5pZnkAbGV0IG8gPSB7CglmKCkgewoJCWFzc2VydC5vayh0aGlzICE9PSBvKTsKCX0KfTsKKDEsIG8uZikoKTsKKDEsIG8uZilgYDsKCih0cnVlICYmIG8uZikoKTsKKHRydWUgJiYgby5mKWBgOwoKKHRydWUgPyBvLmYgOiBmYWxzZSkoKTsKKHRydWUgPyBvLmYgOiBmYWxzZSlgYDs

Oxc's output

let o = {f() {
	assert.ok(this !== o);
}};
(1, o.f)();
(1, o.f)``;
o.f();
o.f``;
(!0 ? o.f : !1)();
(!0 ? o.f : !1)``;

https://oxc-project.github.io/oxc/playground/?code=3YCAAIAbgICAgICAgIC2mcpqpUVBuJ3I%2BHiR31d004qj5Bgli8IXp4uXuyULHD9UOmdTBRJYluRQbf8p3kvgYoXFzfbW6%2BJ5XvxWlXKndcO6VfFc%2BARAdtxe7ZllDHqLf%2F0dYTa9eCxUx6PSbiS%2FfcMYwA%3D%3D


In short, (true && o.f)``; is simplify to o.f`` , which causes this pointing to a wrong object..

Related:

@Boshen
Copy link
Member

Boshen commented Aug 12, 2024

Oh this is harder than I thought ... the above PR doesn't fix call expressions :-/ I'll revisit this sometime in the future.

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
3 participants