microsoft / microsoft/TypeScript
Unneeded temporary introduced for named class expression with static property initializer
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo i tre esempi TypeScript e confrontando l’output JavaScript attuale con quello desiderato. Traccia come vengono emesse le espressioni di classe con nome e anonime con inizializzatori di proprietà statiche, quindi verifica che l’output generato eviti il temporaneo non necessario preservando il comportamento a runtime.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100