microsoft / microsoft/TypeScript

for..of transform when targetting ES6< [Compiler option]

Aperta
#37,466 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. 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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.