Skip to content

Commit 659fbb3

Browse files
committed
Fixed a bug where ambient types were being emitted
1 parent 7c6601f commit 659fbb3

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

‎apps/api-extractor/src/generators/PackageTypingsGenerator.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ interface IFollowAliasesResult {
6969
* from another source file in the current project.
7070
*/
7171
external: boolean;
72+
73+
/**
74+
* If true, the symbol is exported from a module somewhere. If false, then it's
75+
* a global ambient definition or else a private declaration in the referencing file.
76+
* NOTE: The "external" status is unknown if moduleExport=true.
77+
*/
78+
moduleExport: boolean;
7279
}
7380

7481
export default class PackageTypingsGenerator {
@@ -142,15 +149,26 @@ export default class PackageTypingsGenerator {
142149
// Does it start with something like "'./"?
143150
// If not, then assume it's an import from an external package
144151
if (!/^['"\s]+\.[\/\\]/.test(moduleSpecifier)) {
145-
return { symbol: current, external: true };
152+
return { symbol: current, external: true, moduleExport: true };
146153
}
147154
}
148155
}
149156

150157
current = currentAlias;
151158
}
152159

153-
return { symbol: current, external: false };
160+
// Is it an export? We examine all of the declarations to see if any of them contains
161+
// the "export" keyword.
162+
let moduleExport: boolean = false;
163+
for (const declaration of current.declarations || []) {
164+
const modifiers: ts.ModifierFlags = ts.getCombinedModifierFlags(declaration);
165+
if (modifiers & (ts.ModifierFlags.Export | ts.ModifierFlags.ExportDefault)) {
166+
moduleExport = true;
167+
break;
168+
}
169+
}
170+
171+
return { symbol: current, external: false, moduleExport: moduleExport };
154172
}
155173

156174
public constructor(context: ExtractorContext) {
@@ -317,7 +335,7 @@ export default class PackageTypingsGenerator {
317335

318336
private _fetchEntryForSymbol(symbol: ts.Symbol): Entry | undefined {
319337
const result: IFollowAliasesResult = PackageTypingsGenerator._followAliases(symbol, this._typeChecker);
320-
if (result.external) {
338+
if (result.external || !result.moduleExport) {
321339
return; // external definition
322340
}
323341

0 commit comments

Comments
 (0)