Skip to content

Fix: experimentalDecorators renames class name in object literal key/member name positions#4650

Draft
RyanCavanaugh with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-experimental-decorators-issue
Draft

Fix: experimentalDecorators renames class name in object literal key/member name positions#4650
RyanCavanaugh with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-experimental-decorators-issue

Conversation

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

With experimentalDecorators, the emitter incorrectly renamed identifiers matching the class name even in name positions (object literal keys, method shorthand names, field names) — which are not value references to the class and must not be substituted with the self-reference alias.

@dec
class SessionAuth {
  static requirement() {
    return { SessionAuth: [] }; // was wrongly emitted as { SessionAuth_1: [] }
  }
}

Root cause

visitIdentifier calls GetReferencedValueDeclaration, which falls through to ResolveName for declaration/key positions (the checker doesn't cache symbols there). This finds the class by textual name lookup, causing false substitutions. The prior fix (#3147) covered PropertyAccessExpression.name but missed other name positions.

Changes

  • visitPropertyAssignment (new): Added to the visit switch. Skips the property key identifier for non-computed keys; visits only the initializer (and computed key expression when present).
  • visitPropertyNameOfClassElement: Non-computed member names are now returned as-is without calling VisitNode, preventing visitIdentifier from substituting class member declaration names.
  • hasInternalStaticReference: Added explicit switch cases for KindPropertyAssignment, KindPropertyDeclaration, KindMethodDeclaration, KindGetAccessor, KindSetAccessor that skip declaration name children and only recurse into expression/initializer/body subtrees. No .Parent access (forbidden by forbidparentaccess lint rule in transformers).

…4632)

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix emitted class name with experimental decorators Fix: experimentalDecorators renames class name in object literal key/member name positions Jul 15, 2026
Copilot AI requested a review from RyanCavanaugh July 15, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

experimentalDecorators: a class name used as an object literal key is renamed to the self-reference alias

2 participants