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 visibility checking of mutually recursive exports #19929

Merged
merged 5 commits into from
Nov 21, 2017

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Nov 10, 2017

collectLinkedAliases did some painting of declaration visibility in the declaration emitter. This was bad, as one thing would get painted, then written, then another painted, then written; so if one element referenced another element made visible through an alias, we would issue an error. (And only on the first compile in a program! If emit was called twice, we would succeed!)

Now we do that analysis inside the checker, where it should have been all along.

Fixes #14753
Fixes #17085
Fixes #18634

@weswigham weswigham requested review from sandersn, mhegazy and a user November 10, 2017 21:46
@weswigham weswigham force-pushed the mutually-recursive-exports branch 2 times, most recently from df7c309 to f978d82 Compare November 10, 2017 21:53
@weswigham weswigham force-pushed the mutually-recursive-exports branch from f978d82 to b0c0234 Compare November 17, 2017 21:55
@weswigham
Copy link
Member Author

Now also included is a fix for #17085, since it could not be fixed until the visibility of exports was fixed.

@weswigham weswigham force-pushed the mutually-recursive-exports branch from b0c0234 to c888ea3 Compare November 17, 2017 22:03
@weswigham
Copy link
Member Author

Also fixes #18634.

@@ -23258,6 +23263,7 @@ namespace ts {

function checkExportSpecifier(node: ExportSpecifier) {
checkAliasSymbol(node);
collectLinkedAliases(node.propertyName || node.name, /*setVisibility*/ true); // Collect linked aliases to set visibility links
Copy link
Contributor

Choose a reason for hiding this comment

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

you only need to do this if --declaration is set..

Copy link
Member Author

@weswigham weswigham Nov 21, 2017

Choose a reason for hiding this comment

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

done. collectLinkedAliases doesn't generate any diagnostics on its own, but I can see wanting to avoid the extra work where unneeded.

@@ -1249,10 +1249,18 @@ namespace ts {
writeLine();
}

function bindingNameContainsVisibleBindingElement(node: BindingName): boolean {
return !!node && isBindingPattern(node) && some(node.elements, elem => !isOmittedExpression(elem) && (resolver.isDeclarationVisible(elem) || bindingNameContainsVisibleBindingElement(elem.name)));
Copy link
Contributor

Choose a reason for hiding this comment

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

elem => !isOmittedExpression(elem) && isVariableDeclarationVisible(elem) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@mhegazy mhegazy left a comment

Choose a reason for hiding this comment

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

👍 with comments

@weswigham weswigham force-pushed the mutually-recursive-exports branch from 2c4ec05 to ea41813 Compare November 21, 2017 22:13
@weswigham weswigham merged commit 50866e1 into microsoft:master Nov 21, 2017
@weswigham weswigham deleted the mutually-recursive-exports branch November 21, 2017 23:06
@@ -23258,6 +23263,9 @@ namespace ts {

function checkExportSpecifier(node: ExportSpecifier) {
checkAliasSymbol(node);
if (compilerOptions.declaration) {
collectLinkedAliases(node.propertyName || node.name, /*setVisibility*/ true); // Collect linked aliases to set visibility links
Copy link
Member

Choose a reason for hiding this comment

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

both this comment and the other one seem redundant. And if they're not, then things are actually more complicated than they appear.

Copy link
Member Author

Choose a reason for hiding this comment

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

They didn't feel redundant before I added the setVisibility flag. :(

I'll open a PR to remove them.

errendir added a commit to errendir/TypeScript that referenced this pull request Nov 27, 2017
* origin/master: (28 commits)
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  Removes redundant comments (microsoft#20214)
  Catch illegal jsdoc tags on constructors (microsoft#20045)
  Use stricter types for event bodies
  Use {} instead of any to improve type checking
  Update public API baseline
  Update project on PackageInstalledResponse
  Unswap arguments
  LEGO: check in for master to temporary branch.
  Fix visibility checking of mutually recursive exports (microsoft#19929)
  Add dt baseline folder to gitignore (microsoft#20205)
  Support getJSDocCommentsAndTags for special property assignments (microsoft#20193)
  Clean up outliningElementsCollector (microsoft#20143)
  Correct project root path passed to Typings Installer
  Check hasOwnProperty before copying property
  Convert legacy safe list keys to lowercase on construction
  Port generated lib files (microsoft#20177)
  Clean up lexical classifier (microsoft#20123)
  Allow curly around `@type` jsdoc to be optional (microsoft#20074)
  ...
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants