Skip to content

Arrow function used in for-loop not transformed into javascript function #11024

Closed
@yvbeek

Description

@yvbeek

TypeScript Version: nightly (2.0.0-dev.20160920)
TypeScript Command: tsc --target ES5 test.ts

Code (test.ts)

// This arrow shorthand will be properly transformed
let log = (t) => { console.log(t); };

// The arrow shorthand used in the for-loop won't be properly transformed
let items = [{ name: "A" }, { name: "C" }, { name: "B" }];
for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) {
  console.log(item);
}

becomes

var log = function (t) { console.log(t); };

var items = [{ name: "A" }, { name: "C" }, { name: "B" }];
for (var _i = 0, _a = items.sort((a, b) => a.name.localeCompare(b.name)); _i < _a.length; _i++) {
    var item = _a[_i];
    console.log(item);
}

Expected behavior:

When I target ES5 I don't expect any arrow shorthands to end up in the final JS.

Actual behavior:

You can see that the arrow shorthand after items.sort is still there.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: TransformsRelates to the public transform APIFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions