Skip to content

[engineering] make boilerplate stripper differentiate between tsc and esbuild #252597

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tmm1
Copy link
Contributor

@tmm1 tmm1 commented Jun 27, 2025

typescript compiler emits a method named __decorate [1]
esbuild emits a different method named __decorateClass [2]

ensure the regex differentiates the two and does not clobber esbuild outputs

[1] https://github.com/microsoft/TypeScript/blob/02672d281c26e561708127da1d8d1a6cae45fee2/src/compiler/factory/emitHelpers.ts#L730-L742
[2] https://github.com/evanw/esbuild/blob/f4159a7b823cd5fe2217da2c30e8873d2f319667/internal/runtime/runtime.go#L550-L561

… esbuild

typescript compiler emits a method named `__decorate` [1]
esbuild emits a different method named `__decorateClass` [2]

ensure the regex differentiates the two and does not clobber esbuild outputs

[1] https://github.com/microsoft/TypeScript/blob/02672d281c26e561708127da1d8d1a6cae45fee2/src/compiler/factory/emitHelpers.ts#L730-L742
[2] https://github.com/evanw/esbuild/blob/f4159a7b823cd5fe2217da2c30e8873d2f319667/internal/runtime/runtime.go#L550-L561
Copy link

@DhruvTheDev1 DhruvTheDev1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this still not cause issues as both start with _decorate? Whilst it does reduce false matches, does it still not risk clashing with esbuild's _decorateclass?

@tmm1
Copy link
Contributor Author

tmm1 commented Jun 27, 2025

No, the point is to update the regex to fix the clash.

@@ -18,7 +18,7 @@ export function removeAllTSBoilerplate(source: string) {
const BOILERPLATE = [
{ start: /^var __extends/, end: /^}\)\(\);$/ },
{ start: /^var __assign/, end: /^};$/ },
{ start: /^var __decorate/, end: /^};$/ },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ start: /^var __decorate(?=\()/, end: /^};$/ }, // TypeScript's __decorate
{ start: /^var __decorateClass\b/, end: /^};$/ }, // esbuild's __decorateClass

This should ensure they don't clash and work as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants