Implement ES decorator transform (ESNext -> ES2022)#2926
Implement ES decorator transform (ESNext -> ES2022)#2926jakebailey merged 51 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Implements the ES decorator downlevel transform needed for --target es2022 (from esnext) in the TypeScript-Go emitter pipeline, along with the helper emit support and updated golden baselines to reflect the new output.
Changes:
- Adds ES decorator runtime helpers (
__esDecorate,__runInitializers) to the printer helper set. - Ensures the external helpers import declaration is passed through the module transformer visitor so it’s properly transformed for the output module kind.
- Fixes a named-evaluation check in
getAssignedNameOfPropertyNameand updates many conformance/compiler baselines to match the new decorator transform output.
Reviewed changes
Copilot reviewed 154 out of 273 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/printer/helpers.go | Adds new emit helpers for ES decorators and initializer execution. |
| internal/transformers/moduletransforms/esmodule.go | Visits the external helpers import declaration so it can be transformed appropriately (e.g., import = require → const require). |
| internal/transformers/estransforms/namedevaluation.go | Fixes a computed-property-name check to validate the correct node. |
| testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js | Baseline updated for the corrected external helpers import emission. |
| testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js.diff | Baseline diff updated accordingly. |
| testdata/baselines/reference/submodule/conformance/* | Extensive baseline updates reflecting ES decorator downlevel transform output across many scenarios (classes, fields, accessors, private elements, metadata, named evaluation, using, etc.). |
|
This should be ready for a re-review. I've fixed the comments (to my eye), reordered functions, then went 1:1 down and fixed any minor mismatches. There are no longer any |
...e/submodule/conformance/esDecorators-classDeclaration-simpleTransformation(target=es2022).js
Show resolved
Hide resolved
|
In any case, thanks for sending this @AlCalzone; most everything I pushed was little bits or thing that would have been a bit challenging to describe, but basically everything else seemed good to me 😄 |
|
Thanks for pushing it closer to the finish line! |
weswigham
left a comment
There was a problem hiding this comment.
I think we're basically good now - just some small nits.
| // or the proper es class field transform for the legacy one | ||
| var ( | ||
| NewESNextTransformer = transformers.Chain(newESDecoratorTransformer, newUsingDeclarationTransformer, newClassFieldsTransformer) | ||
| esDecoratorAndClassFields = transformers.Chain(newESDecoratorTransformer, newClassFieldsTransformer) |
There was a problem hiding this comment.
This is gonna be a little spicy when decorators stablize into a year, since implicitly class fields will have to move into the same one, but also be globally first for the legacy transform still. Future problem, though.
| statements = append(statements, externalHelpersImportDeclaration) | ||
| // The helpers import must be visited so that `import x = require("tslib")` | ||
| // (TypeScript-only syntax) is transformed to `const x = require("tslib")` | ||
| // for CJS output files via visitImportEqualsDeclaration. |
There was a problem hiding this comment.
Yeah... looking at it createExternalHelpersImportDeclarationIfNeeded makes an import= and leaves it to the later transform to handle when the file/module is commonjs, however since we can't have a commonjs file that's transformed to, eg, amd or umd anymore, we really should just be making the const in that helper, since there isn't a need for variable output anymore.
We can keep doing this roundabout downleveling, but we don't really have a reason not to generate the right nodes up-front.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 213 out of 402 changed files in this pull request and generated 4 comments.
You can also share your feedback on Copilot code review. Take the survey.
This PR implements the decorator transform portion of #2354
This is the only thing blocking me from adopting
tsgo, so I thought I'd help out by porting the original PR.Disclaimer: This is an entire day worth of Claude Opus tokens. I don't claim I understand how it works, but I did my best to direct Claude to minimize the baseline diffs, of which it removed quite a few.
Fixes #2354