Skip to content

Commit a99341e

Browse files
committed
Fix a bug with handling of "import * as semver from 'semver';"
1 parent 76461e7 commit a99341e

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

apps/api-extractor/src/generators/packageTypings/AstSymbolTable.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ export class AstSymbolTable {
114114
case ts.SyntaxKind.PropertyDeclaration:
115115
case ts.SyntaxKind.InterfaceDeclaration:
116116
case ts.SyntaxKind.FunctionDeclaration:
117+
// ModuleDeclaration is used for both "module" and "namespace" declarations
117118
case ts.SyntaxKind.ModuleDeclaration:
118119
case ts.SyntaxKind.VariableDeclaration:
120+
// This is used for "import * as file from 'file';"
121+
case ts.SyntaxKind.SourceFile:
119122
return true;
120123
}
121124
return false;
@@ -245,8 +248,6 @@ export class AstSymbolTable {
245248

246249
for (const declaration of followedSymbol.declarations || []) {
247250
if (!this.isAstDeclaration(declaration)) {
248-
SymbolAnalyzer.followAliases(symbol, this._typeChecker);
249-
250251
throw new Error('Program Bug: Followed a symbol with an invalid declaration: ' + followedSymbol.name);
251252
}
252253
}

apps/api-extractor/src/generators/packageTypings/SymbolAnalyzer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ export class SymbolAnalyzer {
6969
// 2. Check for any signs that this was imported from an external package
7070
let result: IFollowAliasesResult | undefined;
7171

72-
result = SymbolAnalyzer._followAliasesForExportDeclaration(declaration, current);
72+
result = SymbolAnalyzer._followAliasesForExportDeclaration(declaration, current, typeChecker);
7373
if (result) {
7474
return result;
7575
}
7676

77-
result = SymbolAnalyzer._followAliasesForImportDeclaration(declaration, current);
77+
result = SymbolAnalyzer._followAliasesForImportDeclaration(declaration, current, typeChecker);
7878
if (result) {
7979
return result;
8080
}
@@ -125,7 +125,7 @@ export class SymbolAnalyzer {
125125
* Helper function for _followAliases(), for handling ts.ExportDeclaration patterns
126126
*/
127127
private static _followAliasesForExportDeclaration(declaration: ts.Declaration,
128-
symbol: ts.Symbol): IFollowAliasesResult | undefined {
128+
symbol: ts.Symbol, typeChecker: ts.TypeChecker): IFollowAliasesResult | undefined {
129129

130130
const exportDeclaration: ts.ExportDeclaration | undefined
131131
= TypeScriptHelpers.findFirstParent<ts.ExportDeclaration>(declaration, ts.SyntaxKind.ExportDeclaration);
@@ -165,7 +165,7 @@ export class SymbolAnalyzer {
165165

166166
if (modulePath) {
167167
return {
168-
followedSymbol: symbol,
168+
followedSymbol: TypeScriptHelpers.followAliases(symbol, typeChecker),
169169
localName: exportName,
170170
astImport: new AstImport({ modulePath, exportName }),
171171
isAmbient: false
@@ -182,7 +182,7 @@ export class SymbolAnalyzer {
182182
* Helper function for _followAliases(), for handling ts.ImportDeclaration patterns
183183
*/
184184
private static _followAliasesForImportDeclaration(declaration: ts.Declaration,
185-
symbol: ts.Symbol): IFollowAliasesResult | undefined {
185+
symbol: ts.Symbol, typeChecker: ts.TypeChecker): IFollowAliasesResult | undefined {
186186

187187
const importDeclaration: ts.ImportDeclaration | undefined
188188
= TypeScriptHelpers.findFirstParent<ts.ImportDeclaration>(declaration, ts.SyntaxKind.ImportDeclaration);
@@ -260,7 +260,7 @@ export class SymbolAnalyzer {
260260

261261
if (modulePath) {
262262
return {
263-
followedSymbol: symbol,
263+
followedSymbol: TypeScriptHelpers.followAliases(symbol, typeChecker),
264264
localName: symbol.name,
265265
astImport: new AstImport({ modulePath, exportName }),
266266
isAmbient: false

0 commit comments

Comments
 (0)