mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:13:31 -06:00
Fix auto imports for export default edge cases (#41068)
This commit is contained in:
parent
4bf8ac25be
commit
83d02a5f05
@ -622,7 +622,13 @@ namespace ts.codefix {
|
||||
|
||||
if (defaultExport.flags & SymbolFlags.Alias) {
|
||||
const aliased = checker.getImmediateAliasedSymbol(defaultExport);
|
||||
return aliased && getDefaultExportInfoWorker(aliased, Debug.checkDefined(aliased.parent, "Alias targets of default exports must have a parent"), checker, compilerOptions);
|
||||
if (aliased && aliased.parent) {
|
||||
// - `aliased` will be undefined if the module is exporting an unresolvable name,
|
||||
// but we can still offer completions for it.
|
||||
// - `aliased.parent` will be undefined if the module is exporting `globalThis.something`,
|
||||
// or another expression that resolves to a global.
|
||||
return getDefaultExportInfoWorker(aliased, aliased.parent, checker, compilerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultExport.escapedName !== InternalSymbolName.Default &&
|
||||
|
||||
17
tests/cases/fourslash/importNameCodeFixDefaultExport6.ts
Normal file
17
tests/cases/fourslash/importNameCodeFixDefaultExport6.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: /a.ts
|
||||
//// export default Math.foo;
|
||||
|
||||
// @Filename: /index.ts
|
||||
//// a/**/
|
||||
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "a",
|
||||
source: "/a",
|
||||
description: `Import default 'a' from module "./a"`,
|
||||
newFileContent: `import a from "./a";\n\na`,
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true
|
||||
}
|
||||
});
|
||||
14
tests/cases/fourslash/importNameCodeFixDefaultExport7.ts
Normal file
14
tests/cases/fourslash/importNameCodeFixDefaultExport7.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @lib: dom
|
||||
|
||||
// @Filename: foo.ts
|
||||
//// export default globalThis.localStorage;
|
||||
|
||||
// @Filename: index.ts
|
||||
//// foo/**/
|
||||
|
||||
goTo.marker("");
|
||||
verify.importFixAtPosition([`import foo from "./foo";
|
||||
|
||||
foo`]);
|
||||
Loading…
x
Reference in New Issue
Block a user