Repository navigation
Fix ES decorator metadata crash when class extends null - #65364
Open
Yusuf YILDIZ (yusufyildiz34) wants to merge 1 commit into
Open
Yusuf YILDIZ (yusufyildiz34) wants to merge 1 commit into
Yusuf YILDIZ (yusufyildiz34) wants to merge 1 commit into
Conversation
The downleveled decorator metadata code read `_classSuper[Symbol.metadata]`,
which throws a TypeError when the superclass is `null`
(`class C extends null {}`), so the module failed to load.
Emit `_classSuper?.[Symbol.metadata] ?? null` instead, so a null superclass
gives a null parent metadata object, as the decorator metadata proposal
specifies. Targets below ES2020 get the existing optional chaining and
nullish coalescing downlevel.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the null-superclass decorator metadata fix.
No open issues 🎉
What changed in this PR
Fixes #65363 in the native TypeScript compiler by making decorator metadata initialization safe when a class extends null.
Changes:
- Emits
_classSuper?.[Symbol.metadata] ?? null, using existing downlevel transforms for targets below ES2020. - Adds ES2022 and ES2015 regression coverage for literal and potentially null superclasses.
- Updates 21 existing emit baselines to reflect the guarded metadata access.
| File | Description |
|---|---|
tsc/testdata/tests/cases/conformance/esDecorators/metadata/esDecoratorsMetadata6.ts |
Adds null-superclass regression cases. |
tsc/testdata/baselines/reference/conformance/esDecoratorsMetadata6(target=es2022).js |
Records new ES2022 emit. |
tsc/testdata/baselines/reference/conformance/esDecoratorsMetadata6(target=es2015).js |
Records new downleveled ES2015 emit. |
tsc/testdata/baselines/reference/conformance/esDecoratorsMetadata3(target=es2022).js |
Updates class metadata inheritance emit. |
tsc/testdata/baselines/reference/conformance/esDecoratorsMetadata3(target=es2015).js |
Updates downleveled class metadata emit. |
tsc/testdata/baselines/reference/conformance/esDecoratorsMetadata2(target=es2022).js |
Updates method metadata inheritance emit. |
tsc/testdata/baselines/reference/conformance/esDecoratorsMetadata2(target=es2015).js |
Updates downleveled method metadata emit. |
tsc/testdata/baselines/reference/conformance/esDecorators-classExpression-classSuper.6.js |
Updates class-expression metadata guard. |
tsc/testdata/baselines/reference/conformance/esDecorators-classExpression-classSuper.5.js |
Updates class-expression metadata guards. |
tsc/testdata/baselines/reference/conformance/esDecorators-classExpression-classSuper.4.js |
Updates class-expression metadata guard. |
tsc/testdata/baselines/reference/conformance/esDecorators-classExpression-classSuper.3.js |
Updates class-expression metadata guard. |
tsc/testdata/baselines/reference/conformance/esDecorators-classExpression-classSuper.2.js |
Updates class-expression metadata guards. |
tsc/testdata/baselines/reference/conformance/esDecorators-classExpression-classSuper.1.js |
Updates class-expression metadata guard. |
tsc/testdata/baselines/reference/conformance/esDecorators-classDeclaration-classSuper.7.js |
Updates member-decorated class metadata guards. |
tsc/testdata/baselines/reference/conformance/esDecorators-classDeclaration-classSuper.6.js |
Updates class-declaration metadata guard. |
tsc/testdata/baselines/reference/conformance/esDecorators-classDeclaration-classSuper.5.js |
Updates class-declaration metadata guards. |
tsc/testdata/baselines/reference/conformance/esDecorators-classDeclaration-classSuper.4.js |
Updates class-declaration metadata guard. |
tsc/testdata/baselines/reference/conformance/esDecorators-classDeclaration-classSuper.3.js |
Updates class-declaration metadata guard. |
tsc/testdata/baselines/reference/conformance/esDecorators-classDeclaration-classSuper.2.js |
Updates class-declaration metadata guards. |
tsc/testdata/baselines/reference/conformance/esDecorators-classDeclaration-classSuper.1.js |
Updates class-declaration metadata guard. |
tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.js |
Updates metadata emit in an existing regression baseline. |
tsc/testdata/baselines/reference/compiler/malformedDestructuringAssignmentTransformVariants(experimentaldecorators=false,target=es2022).js |
Updates ES2022 metadata emit. |
tsc/testdata/baselines/reference/compiler/malformedDestructuringAssignmentTransformVariants(experimentaldecorators=false,target=es2015).js |
Updates downleveled ES2015 metadata emit. |
tsc/testdata/baselines/reference/compiler/esDecoratorExtendsNull.js |
Updates existing null-superclass metadata emit. |
tsc/internal/transformers/estransforms/esdecorator.go |
Generates optional superclass metadata access. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #65363
The downleveled metadata code now emits
_classSuper?.[Symbol.metadata] ?? null, so anullsuperclass gives anullparent metadata object instead of throwing. Targets below ES2020 get the existing optional chaining and nullish coalescing downlevel.esDecoratorsMetadata6.ts(es2022, es2015), coveringextends nulland a superclass that may benull._metadataline.npx hereby test,npx hereby lint,npx hereby check:format.AI disclosure: I used an AI coding assistant while preparing this change. I have reviewed the patch, understand it, and will handle review feedback myself.