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 targeting ES2017, ESBuild will output public class fields like:
__publicField(this, "propName")
I am using Terser for post-processing with property mangling by Regex enabled. Terser is not able to recognise the string in the function argument as a property to mangle, which makes it incompatible.
The same could be achieved with:
__publicField(this,{propName: ''})
at a small cost of being more verbose and some runtime footprint to get Object.keys(arg)[0] It could be an option / not enabled by default.
Alternatively, is there a reason why Object.defineProperty is not used? This is something that Terser makes an exception for, TypeScript also outputs JS this way.
The text was updated successfully, but these errors were encountered:
I think the missing thing for Terser (and for subsequent esbuild runs with --mangle-props) is the addition of a /* @__KEY__ */ comment to annotate the string literals as property keys. Both Terser and esbuild already have a feature where you can annotate strings with /* @__KEY__ */. That change would look like this:
Alternatively, is there a reason why Object.defineProperty is not used? This is something that Terser makes an exception for, TypeScript also outputs JS this way.
Calling Object.defineProperty instead of using a helper function has non-trivial run-time overhead. It makes the generated code both download and run more slowly.
Thanks! Yes, I confirm Terser handles the annotation.
mckravchyk
changed the title
Feature Request: Output __publicField without string literal for property mangling compatibility
Feature Request: Annotate keys in __publicField() for mangling compatibility
Jan 18, 2025
When targeting ES2017, ESBuild will output public class fields like:
I am using Terser for post-processing with property mangling by Regex enabled. Terser is not able to recognise the string in the function argument as a property to mangle, which makes it incompatible.
The same could be achieved with:
at a small cost of being more verbose and some runtime footprint to get Object.keys(arg)[0] It could be an option / not enabled by default.
Alternatively, is there a reason why
Object.defineProperty
is not used? This is something that Terser makes an exception for, TypeScript also outputs JS this way.The text was updated successfully, but these errors were encountered: