Repository navigation
Use declared class name for ClassDecoratorContext.name - #64844
Open
Adrián Iglesias Álvarez (adrianiglesiass) wants to merge 1 commit into
Open
Adrián Iglesias Álvarez (adrianiglesiass) wants to merge 1 commit into
Adrián Iglesias Álvarez (adrianiglesiass) wants to merge 1 commit into
Conversation
Reading _classThis.name invokes a user-defined static `name` getter or method, so ctx.name could be something other than the class name. Emit the declared name as a string literal and keep _classThis.name only for anonymous classes, whose name is set by __setFunctionName. Fixes microsoft#62870
Author
|
@microsoft-github-policy-service agree |
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 #62870
Problem
For a decorated class with a declared name, the class decorator context was emitted as
{ kind: "class", name: _classThis.name, ... }. Reading_classThis.nameinvokes a user-defined staticnamegetter or method, socontext.namecould be something other than the class name:Implementation
In
esdecorator.go, when the class has a declared (non-generated) name, the contextnameis now emitted as a string literal (name: "A"). Anonymous classes, includingexport default class {}, which get a generated identifier, keep_classThis.name. For those,__setFunctionNamehas already definednameas an own property, so it isn't shadowed by a staticnamegetter.Tests
esDecoratorClassContextNameShadowedByStaticMember.tscovering a staticnamegetter, a staticname()method, and an anonymous class expression..jsline is thekind: "class", name: ...context object (_classThis.name->"<ClassName>"); the foursourceMapbaselines change only because of the shifted columns.generate,build,test,test:all,lint,format,check:format, package builds/tests,mod tidy -diff,go work sync); all passed with no extra diff.AI disclosure
This PR was authored with Claude Code (Anthropic). I've reviewed and understand the change and will handle the review feedback myself.
🤖 Generated with Claude Code