Microsoft/TypeScript

Unoptimized destructuring compilation

Open

#11,779 opened on Oct 21, 2016

View on GitHub
 (6 comments) (1 reaction) (0 assignees)TypeScript (6,726 forks)batch import
Help WantedSuggestion

Repository metrics

Stars
 (48,455 stars)
PR merge metrics
 (Avg merge 6d 17h) (9 merged PRs in 30d)

Description

TypeScript Version: 2.0

Code

// source ts code
let i = 1000;
while (i--) {
  let [a, b, c] = [1, 2, 3];
}

Expected behavior:

// compiled by babel
var i = 1000;
while (i--) {
  var a = 1;
  var b = 2;
  var c = 3;
}

Actual behavior:

// compiled by tsc
var i = 1000;
while (i--) {
    var _a = [1, 2, 3], a = _a[0], b = _a[1], c = _a[2];
}

On each iteration tsc creates new unnecessary array _a.

Contributor guide