Fix ClassDecoratorContext.name to use literal class name (#62870)#62895
Fix ClassDecoratorContext.name to use literal class name (#62870)#62895AryanBagade wants to merge 3 commits intomicrosoft:mainfrom
Conversation
…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
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
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.
|
@RyanCavanaugh could you please review this PR. |
|
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:
|
When a class has a static
namegetter or property, the decorator context'snameproperty 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.tsclassNameReferencefromfactory.createPropertyAccessExpression(renamedClassThis, "name")to use the literal class name viafactory.createStringLiteralFromNode(node.name), falling back tonode.emitNode?.assignedNamefor anonymous classes.New test:
tests/cases/conformance/esDecorators/classDeclaration/esDecorators-classDeclaration-classDecoratorContextNameStaticGetter.tsnamegetter, staticnameproperty, and normal class.Baseline updates: 170 files
hereby baseline-acceptname: _classThis.name→ `name: "ClassName"Emitted code change
Before:
After:
Checklist
Backlogmilestone (required)mainbranchhereby runtestslocallyFixes #62870