Skip to content

Fix ClassDecoratorContext.name to use literal class name (#62870)#62895

Closed
AryanBagade wants to merge 3 commits intomicrosoft:mainfrom
AryanBagade:fix/62870-class-decorator-context-name
Closed

Fix ClassDecoratorContext.name to use literal class name (#62870)#62895
AryanBagade wants to merge 3 commits intomicrosoft:mainfrom
AryanBagade:fix/62870-class-decorator-context-name

Conversation

@AryanBagade
Copy link

When a class has a static name getter or property, the decorator context's name property was incorrectly returning the getter's value instead of the actual class name.

This changes the emitted code from:
{ kind: "class", name: _classThis.name, ... }
to:
{ kind: "class", name: "ClassName", ... }

Changes

Source change: src/compiler/transformers/esDecorators.ts

  • Changed classNameReference from factory.createPropertyAccessExpression(renamedClassThis, "name") to use the literal class name via factory.createStringLiteralFromNode(node.name), falling back to node.emitNode?.assignedName for anonymous classes.

New test: tests/cases/conformance/esDecorators/classDeclaration/esDecorators-classDeclaration-classDecoratorContextNameStaticGetter.ts

  • Tests class decorator context name with static name getter, static name property, and normal class.

Baseline updates: 170 files

  • All baseline changes are auto-generated via hereby baseline-accept
  • Every change is the same pattern: name: _classThis.name → `name: "ClassName"

Emitted code change

Before:

__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);

After:

__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: "C", metadata: _metadata }, null, _classExtraInitializers);

Checklist

  • There is an associated issue in the Backlog milestone (required)
  • Code is up-to-date with the main branch
  • You've successfully run hereby runtests locally
  • There are new or updated unit tests validating the change

Fixes #62870

…2870)

When a class has a static `name` getter or property, the decorator context's `name` property was incorrectly returning the getter's value instead of the actual class name.

This changes the emitted code from:
{ kind: "class", name: _classThis.name, ... }
to:
{ kind: "class", name: "ClassName", ... }

Fixes microsoft#62870
Copilot AI review requested due to automatic review settings December 13, 2025 09:25
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Dec 13, 2025
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Dec 13, 2025
@AryanBagade
Copy link
Author

@microsoft-github-policy-service agree

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where ClassDecoratorContext.name was incorrectly returning the value of a static name getter/property instead of the actual class name. The fix changes the emitted code to use a string literal of the class name rather than dynamically accessing _classThis.name.

Key changes:

  • Modified class decorator context emission to use literal class names instead of runtime property access
  • Added comprehensive test coverage for the issue scenarios
  • Updated all affected baseline files (170 files) with the corrected emission pattern

Reviewed changes

Copilot reviewed 170 out of 172 changed files in this pull request and generated no comments.

File Description
src/compiler/transformers/esDecorators.ts Fixed emission to use factory.createStringLiteralFromNode(node.name) instead of property access
tests/cases/conformance/esDecorators/classDeclaration/esDecorators-classDeclaration-classDecoratorContextNameStaticGetter.ts New test covering static name getter, static name property, and normal class scenarios
170 baseline files All updated with the new emission pattern name: "ClassName" instead of name: _classThis.name

The implementation looks solid. The source code change correctly uses factory.createStringLiteralFromNode(node.name) to generate a string literal from the class name, and falls back to node.emitNode?.assignedName ?? factory.createStringLiteral("") for anonymous classes. The test coverage is appropriate for the bug being fixed.

@AryanBagade
Copy link
Author

@RyanCavanaugh could you please review this PR.
Thanks 👍🏻

@typescript-bot
Copy link
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ES ClassDecoratorContext.name has incorrect value with static name

3 participants