Skip to content

Commit 765114f

Browse files
author
Andy Hanson
committed
Refactor to move code into checker
1 parent 890676a commit 765114f

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace ts {
108108
getAliasedSymbol: resolveAlias,
109109
getEmitResolver,
110110
getExportsOfModule: getExportsOfModuleAsArray,
111-
resolveExternalModuleSymbol,
111+
getExportsAndPropertiesOfModule,
112112
getAmbientModules,
113113
getJsxElementAttributesType,
114114
getJsxIntrinsicTagNames,
@@ -1528,6 +1528,15 @@ namespace ts {
15281528
return symbolsToArray(getExportsOfModule(moduleSymbol));
15291529
}
15301530

1531+
function getExportsAndPropertiesOfModule(moduleSymbol: Symbol): Symbol[] {
1532+
const exports = getExportsOfModuleAsArray(moduleSymbol);
1533+
const exportEquals = resolveExternalModuleSymbol(moduleSymbol);
1534+
if (exportEquals !== moduleSymbol) {
1535+
addRange(exports, getPropertiesOfType(getTypeOfSymbol(exportEquals)));
1536+
}
1537+
return exports;
1538+
}
1539+
15311540
function tryGetMemberInModuleExports(memberName: string, moduleSymbol: Symbol): Symbol | undefined {
15321541
const symbolTable = getExportsOfModule(moduleSymbol);
15331542
if (symbolTable) {

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,8 @@ namespace ts {
23702370
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
23712371
getAliasedSymbol(symbol: Symbol): Symbol;
23722372
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
2373-
/* @internal */ resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol;
2373+
/** Unlike `getExportsOfModule`, this includes properties of an `export =` value. */
2374+
/* @internal */ getExportsAndPropertiesOfModule(moduleSymbol: Symbol): Symbol[];
23742375

23752376
getJsxElementAttributesType(elementNode: JsxOpeningLikeElement): Type;
23762377
getJsxIntrinsicTagNames(): Symbol[];

src/services/completions.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,20 +1318,14 @@ namespace ts.Completions {
13181318
isMemberCompletion = true;
13191319
isNewIdentifierLocation = false;
13201320

1321-
let exports: Symbol[];
1322-
const moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importOrExportDeclaration.moduleSpecifier);
1323-
if (moduleSpecifierSymbol) {
1324-
exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol);
1325-
const exportEquals = typeChecker.resolveExternalModuleSymbol(moduleSpecifierSymbol);
1326-
if (exportEquals !== moduleSpecifierSymbol) {
1327-
// Location doesn't matter so long as it's not an identifier.
1328-
const exportEqualsType = typeChecker.getTypeOfSymbolAtLocation(exportEquals, moduleSpecifier);
1329-
exports = ts.concatenate(exports, typeChecker.getPropertiesOfType(exportEqualsType));
1330-
}
1321+
const moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(moduleSpecifier);
1322+
if (!moduleSpecifierSymbol) {
1323+
symbols = emptyArray;
1324+
return true;
13311325
}
13321326

1333-
symbols = exports ? filterNamedImportOrExportCompletionItems(exports, namedImportsOrExports.elements) : emptyArray;
1334-
1327+
const exports = typeChecker.getExportsAndPropertiesOfModule(moduleSpecifierSymbol);
1328+
symbols = filterNamedImportOrExportCompletionItems(exports, namedImportsOrExports.elements);
13351329
return true;
13361330
}
13371331

0 commit comments

Comments
 (0)