microsoft / microsoft/TypeScript
for..of transform when targetting ES6< [Compiler option]
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
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.
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 mit der Überprüfung der bestehenden for..of-Transformation und der Compiler-Option downlevelIteration und vergleiche anschließend die ausgegebene Ausgabe für ES5- und ES6-oder-neuere Ziele. Das Issue nennt keine Dateien oder Tests; als abgeschlossen würde eine definierte Option, eine verhaltensbewahrende Transformation und eine Abdeckung der gezeigten Array-Schleifenfälle vorausgesetzt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100