Skip to content

Block scope support is broken #6462

@eekboom

Description

@eekboom

TypeScript 1.7.5 does not support the block scope for y here when emitting code for ES5:

function test() {
    let x = 42;
    {
        let x = 43;
        console.log(x);
    }

    {
        let y = 77;
        console.log(y);
    }
    {
        let y = 88;
        console.log(y);
    }
}

Compilation result:

function test() {
    var x = 42;
    {
        var x_1 = 43;
        console.log(x_1);
    }
    {
        var y = 77;
        console.log(y);
    }
    {
        var y = 88;
        console.log(y);
    }
}

At least one of the y's should also have been renamed.

(In my "real" code instead of "console.log()" there are local functions that use y and are registered as callbacks. The first function incorrectly uses the value from the second block.)

Related to #1690

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions