Skip to content

Bad esnext emit for static property that references another static property when the class has a decoratorΒ #44908

Description

Bug Report

πŸ”Ž Search Terms

decorator static usedefineforclassfields

πŸ•— Version & Regression Information

  • In the Playground, this behaviour first appears in 3.7.5.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function foo(ctor: Function) {}
@foo
class C {
	static X = 1;
	static Y = C.X;
}

πŸ™ Actual behavior

When targeting esnext, the useDefineForClassFields option is set by default. Using this combination of options, class C is emitted as follows:

let C = C_1 = class C {
    static X = 1;
    static Y = C_1.X;
};

The name mangling to C_1 causes the assignment to Y to fail at runtime.

If the decorator is removed, the emit becomes:

class C {
    static X = 1;
    static Y = C.X;
}

which works fine.

If useDefineForClassFields is disabled, the property assignment gets moved outside the class definition, where the name mangling is correct.

πŸ™‚ Expected behavior

Probably just not performing the name mangling when emitting within the class.

I appreciate the decorator functionality is unstable, so please consider this bug report purely informational.

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions