Skip to content

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

@hyf0

Description

@hyf0

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:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions