Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yvbeek opened this issue Sep 21, 2016 · 1 comment
Closed
Assignees
Labels
Bug A bug in TypeScript Domain: Transforms Relates to the public transform API Fixed A PR has been merged for this issue

Comments

@yvbeek
Copy link

yvbeek commented Sep 21, 2016

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.

@mhegazy mhegazy added the Bug A bug in TypeScript label Sep 21, 2016
@mhegazy mhegazy added this to the TypeScript 2.1 milestone Sep 21, 2016
@mhegazy mhegazy added the Domain: Transforms Relates to the public transform API label Sep 21, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 21, 2016

@rbuckton can you take a look

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Sep 26, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: Transforms Relates to the public transform API Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants