Skip to content
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

Temporary variable declared too late #15306

Closed
peblpebl opened this issue Apr 21, 2017 · 5 comments
Closed

Temporary variable declared too late #15306

peblpebl opened this issue Apr 21, 2017 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@peblpebl
Copy link

peblpebl commented Apr 21, 2017

Code

var _b;
class C {
    static properties: { [key: string]: string } = {
        ["foo"] : "bar1",        
    };
    static otherproperties = (_b = {}, _b["foo"] = "bar2", _b);
}

// Use C
console.log(C.properties["foo"] + " " + C.otherproperties["foo"])
// End of original src

Expected behavior:

I would have expected that the sugar/javascript for constructing 'properties' would have declared the tmp variable before the construction. In the compile js the _a is declared after the last expression (but before that last comment??).

Google closure compiler warns about this.

Actual behavior:

var _b;
var C = (function () {
    function C() {
    }
    return C;
}());
C.properties = (_a = {},
    _a["foo"] = "bar1",
    _a);
C.otherproperties = (_b = {}, _b["foo"] = "bar2", _b);
// Use C
console.log(C.properties["foo"] + " " + C.otherproperties["foo"]);
var _a;
// End of original src
@ahejlsberg
Copy link
Member

See #4138 and #7297.

@peblpebl
Copy link
Author

This issue is better explained in #4138.

@peblpebl
Copy link
Author

Hmm, this is not quite the same.
In #4138 and #7397 the declaration is in a function and if I understand ecma script correct - then valid everywhere within that function.

_a is not declared in a function here?

@peblpebl peblpebl reopened this Apr 24, 2017
@RyanCavanaugh
Copy link
Member

It doesn't matter. All var declarations are hoisted to the top of their enclosing lexical scope

@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 24, 2017
@mhegazy
Copy link
Contributor

mhegazy commented May 8, 2017

This issue seems to have been already addressed or is unactionable at the moment. I am auto-closing it for now.

@mhegazy mhegazy closed this as completed May 8, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants