Skip to content

Fix ES decorator metadata crash when class extends null - #65364

Open
Yusuf YILDIZ (yusufyildiz34) wants to merge 1 commit into
microsoft:mainfrom
yusufyildiz34:fix-esdecorator-extends-null-metadata
Open

Yusuf YILDIZ (yusufyildiz34) wants to merge 1 commit into
microsoft:mainfrom
yusufyildiz34:fix-esdecorator-extends-null-metadata

Conversation

@yusufyildiz34

Copy link
Copy Markdown
Contributor

Fixes #65363

The downleveled metadata code now emits _classSuper?.[Symbol.metadata] ?? null, so a null superclass gives a null parent metadata object instead of throwing. Targets below ES2020 get the existing optional chaining and nullish coalescing downlevel.

  • Added esDecoratorsMetadata6.ts (es2022, es2015), covering extends null and a superclass that may be null.
  • 21 existing baselines change only the _metadata line.
  • Ran 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.

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.
Copilot AI balanced review requested due to automatic review settings November 6, 2026 18:20
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 6, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

ES decorator metadata emit throws when a decorated class extends null

2 participants