Skip to content

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

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.

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: Not started

Development

Successfully merging this pull request may close these issues.

ES ClassDecoratorContext.name has incorrect value with static name

2 participants