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

Regression: Matched argument name and name of exported function breaks module export #11204

Closed
tsofist opened this issue Sep 28, 2016 · 7 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@tsofist
Copy link

tsofist commented Sep 28, 2016

TypeScript Version: 2.0.3

Code

export {
    my
}

function my() { }

function doSome1(my: any) {
    my = +my;
    return my;
}

function doSome2() {
    const internal = (my: any) => {
        my = +my;
        return my;
    };
    return internal("1");
}

doSome1("1");
doSome2();

Expected behavior:

    function my() { }
    exports.my = my;
    function doSome1(my) {
        my = +my;
        return my;
    }
    function doSome2() {
        var internal = function (my) {
            my = +my;
            return my;
        };
        return internal("1");
    }
    doSome1("1");
    doSome2();

Actual behavior:

    function my() { }
    exports.my = my;
    function doSome1(my) {
        exports.my = my = +my;
        return my;
    }
    function doSome2() {
        var internal = function (my) {
            exports.my = my = +my;
            return my;
        };
        return internal("1");
    }
    doSome1("1");
    doSome2();

_Problem here:_

exports.my = my = +my;
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Sep 28, 2016
@RyanCavanaugh
Copy link
Member

Is this a regression from 1.8?

@tsofist
Copy link
Author

tsofist commented Sep 28, 2016

@RyanCavanaugh yes, it works fine on 1.8.10

@tsofist
Copy link
Author

tsofist commented Sep 28, 2016

Note that it work well if use

export function my() {}

instead of

export {
    my
}

@mhegazy
Copy link
Contributor

mhegazy commented Sep 29, 2016

This is the intended behavior. this was a change in the emitted code in TS 2.0 to match the ES6 module semantics. export function my exports a declaration my, changing it does not have any impact on that. whereas export { my} exports the local binding for my. any change to the name should be witnessed by the importing module. see #8739 for more details.

@mhegazy mhegazy closed this as completed Sep 29, 2016
@mhegazy mhegazy added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Bug A bug in TypeScript labels Sep 29, 2016
@tsofist
Copy link
Author

tsofist commented Sep 29, 2016

@mhegazy with all due respect, you are sure that #8739 is related to this situation described?
Argument my of function doSome1 has _no relation_ to the export module.

I think you just do not carefully studied example. And even if it is "Working as Intended" (I really doubt) - it breaks backward compatibility. At the same time, this code works fine in _1.8.10_

@tsofist tsofist changed the title Matched argument name and name of exported function breaks module export Regression: Matched argument name and name of exported function breaks module export Sep 29, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 29, 2016

I actually did not see the function argument. my apologies. i was talking about the function name.

@mhegazy mhegazy added Bug A bug in TypeScript and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Sep 29, 2016
@mhegazy mhegazy added this to the TypeScript 2.0.5 milestone Sep 29, 2016
@mhegazy mhegazy reopened this Sep 29, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 29, 2016

@vladima can you take a look. we need to fix this for release-2.0.5

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Oct 7, 2016
@mhegazy mhegazy closed this as completed Oct 7, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants