Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions apps/api-extractor/src/analyzer/ExportAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,22 @@ export class ExportAnalyzer {
if (exportStarSymbol) {
for (const exportStarDeclaration of exportStarSymbol.getDeclarations() || []) {
if (ts.isExportDeclaration(exportStarDeclaration)) {
const starExportedModule: AstModule | undefined = this._fetchSpecifierAstModule(
exportStarDeclaration,
exportStarSymbol
);
let starExportedModule: AstModule | undefined;

try {
starExportedModule = this._fetchSpecifierAstModule(exportStarDeclaration, exportStarSymbol);
} catch {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this catching Internal Error: getResolvedModule() could not resolve module name? That error is thrown by API Extractor's own implementation. Generally we try to avoid throwing/catching exceptions during normal successful operation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I explained in the PR description:

Why use try...catch? The TypeScriptHelpers.isAmbient cannot working for this, is there a more precise way than try...catch?

Can you provide a better way to catch that?

// handle export star from ambient modules, they are treated as external modules
// such as export * from 'fs' in @types/fs-extra
const sourceFile: ts.SourceFile = exportStarDeclaration.getSourceFile();
const moduleSymbol: ts.Symbol = this._getModuleSymbolFromSourceFile(sourceFile, undefined);

starExportedModule = new AstModule({
sourceFile,
moduleSymbol,
externalModulePath: this._getModuleSpecifier(exportStarDeclaration)
});
}

if (starExportedModule !== undefined) {
astModule.starExportedModules.add(starExportedModule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class A {

export * from "api-extractor-lib1-test";
export * from "api-extractor-lib2-test";
export * from "fs";

// (No @packageDocumentation comment for this package)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export declare class A {

export * from "api-extractor-lib1-test";
export * from "api-extractor-lib2-test";
export * from "fs";

export { }
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
export * from './reexportStar';

export * from 'api-extractor-lib2-test';
export * from 'fs';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/api-extractor",
"comment": "Fix error for export star from ambient module",
"type": "patch"
}
],
"packageName": "@microsoft/api-extractor"
}