Skip to content

Inconsistent parameter properties initialization order depending on the target syntax with useDefineForClassFields #45995

Open
@nicolo-ribaudo

Description

@nicolo-ribaudo

Bug Report

🔎 Search Terms

properties initialization esnext order initialization fields useDefineForClassFields

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about classes

Ref: babel/babel#13779

⏯ Playground Link

Playground link with relevant code (ES2021 target)

Playground link with relevant code (ESNext target)

💻 Code

new class Dashboard {
    name = console.log(this.amount);
    constructor(public amount: number) {
    }
}(1);

🙁 Actual behavior

When targeting ES2021 this.amount is initialized first; when targeting ESNext this.name is initialized first.

🙂 Expected behavior

They should be consistent.

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeDomain: JS EmitThe issue relates to the emission of JavaScriptRescheduledThis 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