oxc
oxc copied to clipboard
[Compressor|RemoveDeadCode]: Wrong simplified expression in the tagged template
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:
- https://github.com/evanw/esbuild/issues/2610
- https://github.com/swc-project/swc/issues/6146
- https://github.com/rolldown/rolldown/pull/1656#issuecomment-2235544211