microsoft / microsoft/TypeScript
Unneeded temporary introduced for named class expression with static property initializer
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Search Terms
classes, static properties, temporary variable
Suggestion
When a class expression is returned from a function, it gets assigned to a temporary variable that is not needed there.
Use Cases
Less verbose and more clear JavaScript output.
Examples
Input:
const f = () => class { static x = 1; };
const g = () => class _ { static x = 1; };
const h = () => { class _ { static x = 1; } return _; };
Current output (3.7.2) (formatted a little differently):
const f = () => { var _a; return _a = class { }, _a.x = 1, _a; };
const g = () => { var _a; return _a = class _ { }, _a.x = 1, _a; };
const h = () => { class _ { }; _.x = 1; return _; };
Desired output:
const f = () => { var _a = class { }; _a.x = 1; return _a; };
const g = () => { class _ { } _.x = 1; return _; };
const h = () => { class _ { } _.x = 1; return _; };
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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.
Rechercherichtung
Beginne damit, die drei TypeScript-Beispiele zu reproduzieren und die aktuelle JavaScript-Ausgabe mit der gewünschten Ausgabe zu vergleichen. Verfolge, wie benannte und anonyme Klassenausdrücke mit statischen Property-Initialisierern ausgegeben werden, und überprüfe anschließend, dass die generierte Ausgabe das unnötige temporäre Zwischenobjekt vermeidet und dabei das Laufzeitverhalten beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100