Skip to content

Static property references incorrect class name with es2022 target and keepClassNames enabled #8039

Description

@anytinz

Describe the bug

When target is es2022 and keepClassNames is enabled, the static property of a class that uses a decorator uses the wrong class name when referencing its own other static property.

Also, as I tested, the tranform result is as expected in all of the following options:

  • target: es2022, keepClassNames: false
  • target: es2021, keepClassNames: true
  • target: es2021, keepClassNames: false

Input code

No response

Config

No response

Playground link

https://play.swc.rs/?version=1.3.90&code=H4sIAAAAAAAAA42P0QrCIBSG7wXf4VxuN0Gb7iJYFNVlewcxiWApqF3F3j3Pok1pwi4E%2FTzn%2F%2FhvSvbCKpBGOw9nJY0V3tgdFCW0ezj1wrmJUkKJRBK428KbEgDnhX9I6I7XC7Qj32jxVPiFB%2B8pR3pXvguP4BgzAKzyL6u%2FYxiFdKBkSIxVxlhFybPvR9OMOpNRx9OHqXFRRrsss8sW%2FWxdX%2FbXN2PnGTtftPMVfZpMYjPvfgA4YuxpHwIAAA%3D%3D&config=H4sIAAAAAAAAA02LOw7CQAwF%2B5xi5ZoCbUmbnjtYmxe0IZ%2BVbSRWUe6OCQTR%2Bc141iYEGjTRJax%2B%2BigsCvltJ1pn46cTslqgSXIxOh22Q1qEbRH1D5MHdrF9PBnLDfZuofEc47ejO1DakVWvPOGv3Dua8pz76rTnUdFsL%2Boq0SamAAAA

SWC Info output

No response

Expected behavior

The Class referenced by the static property in Cls4, Cls5 should be Cls4, Cls5 respectively:

...

let Cls4 = class Cls4 {
    static NAME = Cls4.name;
    name = Cls4.name;
    getName() {
        return Cls4.NAME;
    }
};
Cls4 = _ts_decorate([
    Decorator()
], Cls4);
let Cls5 = class Cls5 {
    static NAME = Cls5.name;
    name = Cls5.name;
};
Cls5 = _ts_decorate([
    Decorator()
], Cls5);

...

Actual behavior

No response

Version

1.3.90

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions