Skip to content

Down-level destructuring in for..in statement #3715

@rbuckton

Description

@rbuckton

We report an error for the following code, :

for (var {toString} in { a: 1 }) { // error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern.
   console.log(toString);
}

We also emit the following incorrect javascript:

for (var toString = (void 0).toString in { a: 1 }) {
    console.log(toString);
}

We should instead emit:

for (var _a in { a: 1 }) {
    var toString = _a.toString;
    console.log(toString);
}

While it is unlikely this will be very useful, this is another of the ES6 compatibility tests on the kangax compatibility table that we could consider addressing as it seems a small enough change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptES6Relates to the ES6 Spec

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions