Skip to content

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

Closed

Description

@tsofist

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;

Activity

  1. RyanCavanaugh commented on Sep 28, 2016

    @RyanCavanaugh
    Member

    Is this a regression from 1.8?

  2. tsofist commented on Sep 28, 2016

    @tsofist
    Author

    Ryan Cavanaugh (@RyanCavanaugh) yes, it works fine on 1.8.10

  3. tsofist commented on Sep 28, 2016

    @tsofist
    Author

    Note that it work well if use

    export function my() {}

    instead of

    export {
        my
    }
  4. mhegazy commented on Sep 29, 2016

    @mhegazy
    Contributor

    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.

  5. added
    Working as IntendedThe behavior described is the intended behavior; this is not a bug
    and removed
    BugA bug in TypeScript
    on Sep 29, 2016
  6. tsofist commented on Sep 29, 2016

    @tsofist
    Author

    Mohamed Hegazy (@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_

  7. 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[/+] on Sep 29, 2016
  8. mhegazy commented on Sep 29, 2016

    @mhegazy
    Contributor

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

  9. added
    BugA bug in TypeScript
    and removed
    Working as IntendedThe behavior described is the intended behavior; this is not a bug
    on Sep 29, 2016
  10. mhegazy commented on Sep 29, 2016

    @mhegazy
    Contributor

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

  11. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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