Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix __setFunctionName overriding custom static name property#62902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
pranshugupta01 wants to merge3 commits intomicrosoft:main
base:main
Choose a base branch
Loading
frompranshugupta01:fix/setFunctionName-static-name

Conversation

@pranshugupta01
Copy link

@pranshugupta01pranshugupta01 commentedDec 15, 2025
edited
Loading

This PRfixes#62854 where the __setFunctionName helper unconditionally overwrites custom static name properties (getters, methods, accessors) on decorated classes.

The Problem

const dec = (c: any) => c;@dec class MyClass {    static get name() { return 2434; }}console.log(MyClass.name);// Expected: 2434// Actual: "MyClass" ❌ — custom getter was overwritten!

The error occurred because __setFunctionName used Object.defineProperty to unconditionally set the name property, ignoring any custom static name getter, method, or accessor defined by the user.

The Fix:
Modified the __setFunctionName helper in src/compiler/factory/emitHelpers.ts to check the existing property descriptor before overwriting:

var __setFunctionName = function (f, name, prefix) {    if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";    var d = Object.getOwnPropertyDescriptor(f, "name");    if (d && d.writable !== false) return f;  // Don't override custom definitions    return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });};

Testing

  • Added test case esDecorators-classDeclaration-staticName.ts covering:
  • Decorated class with static get name()
  • Decorated class with static name() method
  • Decorated anonymous class with custom name getter
  • Decorated class without custom name (automatic name still works)
  • Decorated class with static name field

Baseline Changes

New baselines:

  • esDecorators-classDeclaration-staticName(target=es2022).js
  • esDecorators-classDeclaration-staticName(target=esnext).js
  • Updated baselines (helper text changed with 2 new lines):
  • esDecorators-classDeclaration-sourceMap (es2015, es2022)
  • esDecoratorsClassFieldsCrash.js
  • esDecoratorsMetadata1-4 (es2015)

All 99,167 tests pass.

@pranshugupta01
Copy link
Author

@microsoft-github-policy-service agree

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

For Backlog BugPRs that fix a backlog bug

Projects

Status: Not started

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

__setFunctionName breaks custom staticname on classes

2 participants

@pranshugupta01@typescript-bot

[8]ページ先頭

©2009-2025 Movatter.jp