Skip to content

Commit 5b870cc

Browse files
committed
Fix up ApiModelGenerator and ReviewFileGenerator to handle reexported declarations (i.e. where both CollectorEntity.exported=true and AstSymbol.imported=true)
1 parent c0bed78 commit 5b870cc

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

apps/api-extractor/src/generators/ApiModelGenerator.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ export class ApiModelGenerator {
6464
for (const entity of this._collector.entities) {
6565
for (const astDeclaration of entity.astSymbol.astDeclarations) {
6666
if (entity.exported) {
67-
this._processDeclaration(astDeclaration, entity.nameForEmit, apiEntryPoint);
67+
if (!entity.astSymbol.imported) {
68+
this._processDeclaration(astDeclaration, entity.nameForEmit, apiEntryPoint);
69+
} else {
70+
// TODO: Figure out how to represent reexported definitions. Basically we need to introduce a new
71+
// ApiItem subclass for "export alias", similar to a type alias, but representing declarations of the
72+
// form "export { X } from 'external-package'". We can also use this to solve GitHub issue #950.
73+
}
6874
}
6975
}
7076
}

apps/api-extractor/src/generators/ReviewFileGenerator.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { DeclarationMetadata } from '../collector/DeclarationMetadata';
1414
import { SymbolMetadata } from '../collector/SymbolMetadata';
1515
import { ReleaseTag } from '../aedoc/ReleaseTag';
1616
import { Text, InternalError } from '@microsoft/node-core-library';
17+
import { AstImport } from '../analyzer/AstImport';
1718

1819
export class ReviewFileGenerator {
1920
/**
@@ -35,15 +36,31 @@ export class ReviewFileGenerator {
3536

3637
for (const entity of collector.entities) {
3738
if (entity.exported) {
38-
// Emit all the declarations for this entry
39-
for (const astDeclaration of entity.astSymbol.astDeclarations || []) {
39+
if (!entity.astSymbol.astImport) {
40+
// Emit all the declarations for this entry
41+
for (const astDeclaration of entity.astSymbol.astDeclarations || []) {
4042

41-
output.append(ReviewFileGenerator._getAedocSynopsis(collector, astDeclaration));
43+
output.append(ReviewFileGenerator._getAedocSynopsis(collector, astDeclaration));
4244

43-
const span: Span = new Span(astDeclaration.declaration);
44-
ReviewFileGenerator._modifySpan(collector, span, entity, astDeclaration);
45-
span.writeModifiedText(output);
46-
output.append('\n\n');
45+
const span: Span = new Span(astDeclaration.declaration);
46+
ReviewFileGenerator._modifySpan(collector, span, entity, astDeclaration);
47+
span.writeModifiedText(output);
48+
output.append('\n\n');
49+
}
50+
} else {
51+
// This definition is reexported from another package, so write it as an "export" line
52+
// In general, we don't report on external packages; if that's important we assume API Extractor
53+
// would be enabled for the upstream project. But see GitHub issue #896 for a possible exception.
54+
const astImport: AstImport = entity.astSymbol.astImport;
55+
56+
if (astImport.exportName === '*') {
57+
output.append(`export * as ${entity.nameForEmit}`);
58+
} else if (entity.nameForEmit !== astImport.exportName) {
59+
output.append(`export { ${astImport.exportName} as ${entity.nameForEmit} }`);
60+
} else {
61+
output.append(`export { ${astImport.exportName} }`);
62+
}
63+
output.append(` from '${astImport.modulePath}';\n`);
4764
}
4865
}
4966
}

0 commit comments

Comments
 (0)