-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Fix visibility checking of mutually recursive exports #19929
Conversation
df7c309
to
f978d82
Compare
… statefullness in declaration emit
f978d82
to
b0c0234
Compare
Now also included is a fix for #17085, since it could not be fixed until the visibility of exports was fixed. |
b0c0234
to
c888ea3
Compare
Also fixes #18634. |
src/compiler/checker.ts
Outdated
@@ -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 |
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.
src/compiler/declarationEmitter.ts
Outdated
@@ -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))); |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 with comments
2c4ec05
to
ea41813
Compare
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
* 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) ...
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