microsoft / microsoft/TypeScript
Incorrect class #private fields initialization order with target ES2022 and useDefineForClassFields set to false
@rbuckton arbeitet bereits daran.
Seit 10.5.2023.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Bug Report
🔎 Search Terms
ES2022 class field initialization order
private fields order
useDefineForClassFields false
🕗 Version & Regression Information
- This changed between versions 4.9.5 and 5.0.4
⏯ Playground Link
5.0.4 with runtime error (useDefineForClassFields: false, target: ES2022)
4.9.5 without runtime error (useDefineForClassFields: false, target: ES2022)
💻 Code
class Buzz {
wow = 'one'
}
class Foo {
#bar = this.buz.wow;
constructor(private buz: Buzz) {}
}
new Foo(new Buzz())
🙁 Actual behavior
With 5.0.4 and useDefineForClassFields: false, target: ES2022 the above code fails in runtime because #bar = this.buz.wow; stays initialized before constructor, this doesn't happen if "normal private" is used (private bar = this.buz.wow;). Such construct works without issues on 4.9.5.
🙂 Expected behavior
The initialization is done in the same way as on 4.9.5.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.