Skip to content

Conversation

@weswigham
Copy link
Member

Fixes #37552

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Jul 29, 2020
@weswigham weswigham requested a review from sandersn July 29, 2020 20:39
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

One possible bug and one request for a test.

deferredPrivates.set(getSymbolId(symbol), symbol);
// Blanket moving (import) aliases into the root private context should work, since imports are not valid within namespaces
// (so they must have been in the root to begin with if they were real imports) cjs `require` aliases (an upcoming feature)
// will throw a wrench in this, since those may have been nested, but we'll need to synthesize them in the outer scope
Copy link
Member

Choose a reason for hiding this comment

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

can you add a test for the commonjs case so I'll be forced to fix it before merging that PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean, a copy of jsDeclarationsImportAliasExposedWithinNamespace.ts but with cjs requires instead of import and module.exports instead of export should do; i'll add it, but you'll still need to watch it (since it may do... nothing).

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added jsDeclarationsImportAliasExposedWithinNamespaceCjs.ts - it currently has errors and unexpected output (due to the nested typedefs not resolving correctly with cjs exports).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

const isExternalImportAlias = !!(symbol.flags & SymbolFlags.Alias) && !some(symbol.declarations, d =>
!!findAncestor(d, isExportDeclaration) ||
isNamespaceExport(d) ||
(isImportEqualsDeclaration(d) && !isExternalModuleReference(d.moduleReference))
Copy link
Member

Choose a reason for hiding this comment

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

this last line looks for import x = y, not import x = require('y'), right? I didn't think these declarations needed to be moved, so that seems backwards. But maybe I'm reading it backward.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but that's correct; the logic goes "An alias is an external import alias if it is not an import to any of an export (or any kind) or an alias to a local reference."

@weswigham weswigham requested a review from sandersn July 31, 2020 18:36
deferredPrivates.set(getSymbolId(symbol), symbol);
// Blanket moving (import) aliases into the root private context should work, since imports are not valid within namespaces
// (so they must have been in the root to begin with if they were real imports) cjs `require` aliases (an upcoming feature)
// will throw a wrench in this, since those may have been nested, but we'll need to synthesize them in the outer scope
Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@weswigham weswigham merged commit 9498978 into microsoft:master Aug 1, 2020
@weswigham weswigham deleted the imports-in-root-declaration-context branch August 1, 2020 01:25
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

Errors in generated declaration files

3 participants