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

Fix error on duplicate commonjs exports #40545

Merged
merged 2 commits into from Sep 14, 2020

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Sep 14, 2020

Previously, the code missed setting the parent pointer for the lhs access expression.
Note that this was not previously an error; you can also avoid the error by setting the exclude flags back to None. But I don't think duplicate exports are that common, and non-checkjs users aren't going to see the error anyway.

Also add declaration emit of element access expressions, missed in my previous PR.

Fixes #40513

Previously, the code missed setting the parent pointer for the lhs
access expression.

Also add declaration emit of element access expressions, missed in my
previous PR.
@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 14, 2020
@DanielRosenwasser DanielRosenwasser added the Breaking Change Would introduce errors in existing code label Sep 14, 2020

//// [moduleExportAliasElementAccessExpression.js]
function D() { }
exports["D"] = D;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And non-identifier names, like "A B", emit as...what? Probably needs a test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_A_B. I added a test the in the bug, but I guess I can add it here.

~~~~~~~~~~~~~
!!! error TS2322: Type '() => void' is not assignable to type 'undefined'.
~~~~~
!!! error TS2300: Duplicate identifier 'apply'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get rid of this error, we can defer detection of this case in the binder by removing the offending case from AliasExcludes (like we did for class/function merges) and then look for it in the checker, where we can filter certain declarations (probably undefined assignments) and except it, while retaining the error more generally.

I think this pattern is actually super common, considering it's our current emit for cjs, so we should probably invest the effort into making it work smoothly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our discussion, I switched this to None for the beta. It turns out that the checker already issues an error in this case, but we can add an exclusion for undefined-as-initialiser later.

CommonJS exports have None excludes, but still have an error issued by
the checker. This is the previous behaviour even though it would be nice
to add some exclusions.
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is ok, so long as we're tracking fixing the error more broadly and adding an exception to the checker's duplicate export checking for undefined assignments (because our own emit looks like that). At least for the former, as I mentioned, I am still sliiiiiiightly worried that not using the appropriate exclude flags might result in some order-dependent cross-file merge issues down the line; so fixing it by adjusting the exclude flags themselves may be pertinent in the near future.

@sandersn sandersn merged commit ec36d73 into master Sep 14, 2020
@sandersn sandersn deleted the fix-duplicate-commonjs-exports-error branch September 14, 2020 20:13
@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 14, 2020
@sandersn
Copy link
Member Author

Filed #40555 to follow up.

@DanielRosenwasser DanielRosenwasser removed the Breaking Change Would introduce errors in existing code label Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crash in async from #40228
4 participants