microsoft / microsoft/TypeScript
for..of transform when targetting ES6< [Compiler option]
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
for..of, downlevelIteration, transform, optimization, compiler option
Suggestion
Option for transforming for..of when targetting ES6 and above.
Background
Based on my investigation, for..of loops are slower than the traditional for loops (see the result: https://github.com/aminya/TypeScript-optimization)
It is pretty funny that when I target ES5, TypeScript converts for..of to the traditional loops, which makes the code faster, but I cannot do this when I target anything above ES6.
I noticed that there is "downlevelIteration" which does the opposite of what I want.
Use Cases
It enhances the performance but allows to write readable code.
Examples
// for - of
let sum = 0
for (const a of arr) {
sum += a
}
// should be transformed to:
// Traditional
let sum = 0
for (let i = 0, l = arr.length; i < l; ++i) {
sum += arr[i]
}
// or
let sum = 0
for (let i = 0, l = arr.length; i < l; ++i) {
let a = arr[i]
sum += a
}
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 esaminando la trasformazione for..of esistente e l’opzione del compilatore downlevelIteration, quindi confronta l’output generato per i target ES5 ed ES6 o successivi. L’issue non indica file o test; per considerarla completata servirebbero un’opzione definita, una trasformazione che preservi il comportamento e la copertura dei casi mostrati di cicli sugli array.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100