You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the transform API with syntax lowering (e.g. for classes) or with keepNames (--keep-names), the code generated often look something like this:
Because the __publicField and __name aren't marked as pure (/* @__PURE__ */), even if _Foo is unused, bundlers are not able to assume it's safe to treeshake it. Should esbuild be prepending the /* @__PURE__ */ comments to __publicField and __name?
The __publicField and __name statements are holding a value on _Foo, which prevents it from being treeshaken if the exports are unused in bundlers.
I noticed for function expressions and keepNames, e.g. with export const foo = () => {}, esbuild is already transforming it to export const _foo = /* @__PURE__ */ __name(() => {}, "foo"). This has allowed esbuild to treeshake it if unused.
Perhaps something similar can be done for non-expressions and for the lowering code.
The text was updated successfully, but these errors were encountered:
Ah that pretty much makes this feature request moot then. I don't know if esbuild is up to transforming to that way to solve the treeshaking issue, or if there's some other solution to this.
bluwy
changed the title
Add pure comment for expressions generated from syntax lowering or keepNames
Statements generated from syntax lowering or keepNames block treeshaking
Nov 5, 2024
When using the transform API with syntax lowering (e.g. for classes) or with keepNames (
--keep-names
), the code generated often look something like this:Playground link
Because the__publicField
and__name
aren't marked as pure (/* @__PURE__ */
), even if_Foo
is unused, bundlers are not able to assume it's safe to treeshake it. Should esbuild be prepending the/* @__PURE__ */
comments to__publicField
and__name
?The
__publicField
and__name
statements are holding a value on_Foo
, which prevents it from being treeshaken if the exports are unused in bundlers.I noticed for function expressions and keepNames, e.g. with
export const foo = () => {}
, esbuild is already transforming it toexport const _foo = /* @__PURE__ */ __name(() => {}, "foo")
. This has allowed esbuild to treeshake it if unused.Perhaps something similar can be done for non-expressions and for the lowering code.The text was updated successfully, but these errors were encountered: