-
Notifications
You must be signed in to change notification settings - Fork 12.8k
fix autoimports crash: generate namespace and other module symbol imports #60333
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
Changes from all commits
616c423
1261800
1c1a88e
03ffc58
90e89e6
3ca07d1
a20c2bb
21a6598
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ export const enum ExportKind { | |
Default, | ||
ExportEquals, | ||
UMD, | ||
Module, | ||
} | ||
|
||
/** @internal */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,10 @@ export function addTargetFileImports( | |
if (checker.isUnknownSymbol(targetSymbol)) { | ||
importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor(symbol.declarations?.[0], isAnyImportOrRequireStatement))); | ||
} | ||
else if (targetSymbol.parent === undefined) { | ||
Debug.assert(declaration !== undefined, "expected module symbol to have a declaration"); | ||
importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration); | ||
} | ||
Comment on lines
+83
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why we can't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean in the if statement or the debug statement? The debug is needed since the intent of the importAdder function is to copy from an existing declaration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the if statement, namespaces are specifically not external module symbols, so |
||
else { | ||
importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration); | ||
} | ||
|
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.
I was concerned that there are times this should return
ImportKind.CommonJS
, but I think the critical cases are already covered by the condition at the top of this function. It’s probably fine.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.
I think cases that should return
ImportKind.CommonJs
still crash. #60333 (comment)