Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Naming collision of hidden variables when mixing for-of and spread operator #12830

Copy link
Copy link
@voltrevo

Description

@voltrevo
Issue body actions

TypeScript Version: 2.1.4

Code

function baz(x: any) {
  return [[x, x]];
}

function foo(set: any) {
  for (const [value, i] of baz(set.values)) {
    const bar: any = [];
    (() => bar);

    set.values.push(...[]);
  }
};

Expected behavior:

Names of hidden/implementation variables should not clash.

Actual behavior:

Two _a hidden variables are created which would be in different scopes under ES6 let/const but are in the same scope since they are var:

function baz(x) {
    return [[x, x]];
}
function foo(set) {
    var _loop_1 = function (value, i) {
        var bar = [];
        (function () { return bar; });
        (_a = set.values).push.apply(_a, []);
    };
    for (var _i = 0, _a = baz(set.values); _i < _a.length; _i++) {
        var _b = _a[_i], value = _b[0], i = _b[1];
        _loop_1(value, i);
    }
    var _a;
}
;

Note:

After pruning my code to isolate the issue, I'm not sure what the impact of the collision is anymore, but in my original code I was getting an infinite loop due to the loop index being part of the collision. I should be able to produce a short example like that if needed.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.