Skip to content

Corrected codegen to support shadowed module names. #623

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

Merged
merged 1 commit into from
Sep 8, 2014

Conversation

ahejlsberg
Copy link
Member

Fixes #601.

@ahejlsberg
Copy link
Member Author

For the example

module X.M {
    export var x = false;

    function q(M) {
    }

    M.x = true;
}

we would previously emit

var X;
(function (X) {
    (function (_M) {
        _M.x = false;
        function q(M) {
        }
        M.x = true;  // Crash here, M not yet initialized
    })(X.M || (X.M = {}));
    var M = X.M;
})(X || (X = {}));

With this change we now emit:

var X;
(function (X) {
    var M;
    (function (_M) {
        _M.x = false;
        function q(M) {
        }
        M.x = true;
    })(M = X.M || (X.M = {}));  // Initialize both M and X.M
})(X || (X = {}));

This also brings our code generation for exported modules more in line with non-exported modules by always declaring the local variable before the anonymous function.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 8, 2014

👍

ahejlsberg added a commit that referenced this pull request Sep 8, 2014
Corrected codegen to support shadowed module names.
@ahejlsberg ahejlsberg merged commit 9adb893 into master Sep 8, 2014
@ahejlsberg ahejlsberg deleted the shadowedModuleNames branch September 8, 2014 17:02
@sparecycles
Copy link
Contributor

👍 Thanks!

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad Codegen for ModuleNames shadowed by Parameters
3 participants