Skip to content

Commit 50fa0f6

Browse files
author
Andy
authored
Fix bug: Resolve module symbol before checking whether module export is a re-export (#20989)
* Fix bug: Resolve module symbol before checking whether module export is a re-export * Remove unnecessary @nolib
1 parent f34de1a commit 50fa0f6

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ namespace ts {
273273
},
274274
getJsxNamespace: () => unescapeLeadingUnderscores(getJsxNamespace()),
275275
getAccessibleSymbolChain,
276+
resolveExternalModuleSymbol,
276277
};
277278

278279
const tupleTypes: GenericType[] = [];

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,8 @@ namespace ts {
28742874
* This should be called in a loop climbing parents of the symbol, so we'll get `N`.
28752875
*/
28762876
/* @internal */ getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, useOnlyExternalAliasing: boolean): Symbol[] | undefined;
2877+
2878+
/* @internal */ resolveExternalModuleSymbol(symbol: Symbol): Symbol;
28772879
}
28782880

28792881
/* @internal */

src/services/completions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,10 @@ namespace ts.Completions {
11551155
codefix.forEachExternalModuleToImportFrom(typeChecker, sourceFile, allSourceFiles, moduleSymbol => {
11561156
for (let symbol of typeChecker.getExportsOfModule(moduleSymbol)) {
11571157
// Don't add a completion for a re-export, only for the original.
1158-
// If `symbol.parent !== moduleSymbol`, this comes from an `export * from "foo"` re-export. Those don't create new symbols.
1158+
// If `symbol.parent !== ...`, this comes from an `export * from "foo"` re-export. Those don't create new symbols.
11591159
// If `some(...)`, this comes from an `export { foo } from "foo"` re-export, which creates a new symbol (thus isn't caught by the first check).
1160-
if (symbol.parent !== moduleSymbol || some(symbol.declarations, d => isExportSpecifier(d) && !!d.parent.parent.moduleSpecifier)) {
1160+
if (symbol.parent !== typeChecker.resolveExternalModuleSymbol(moduleSymbol)
1161+
|| some(symbol.declarations, d => isExportSpecifier(d) && !!d.parent.parent.moduleSpecifier)) {
11611162
continue;
11621163
}
11631164

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /a.d.ts
4+
////declare namespace N {
5+
//// export const foo = 0;
6+
////}
7+
////export = N;
8+
9+
// @Filename: /b.ts
10+
////f/**/;
11+
12+
goTo.marker("");
13+
verify.completionListContains({ name: "foo", source: "/a" }, "const N.foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, {
14+
includeExternalModuleExports: true,
15+
sourceDisplay: "./a",
16+
});
17+
18+
verify.applyCodeActionFromCompletion("", {
19+
name: "foo",
20+
source: "/a",
21+
description: `Import 'foo' from module "./a"`,
22+
// TODO: GH#18445
23+
newFileContent: `import { foo } from "./a";\r
24+
\r
25+
f;`,
26+
});

0 commit comments

Comments
 (0)