Skip to content

Commit

Permalink
Fix up ApiModelGenerator and ReviewFileGenerator to handle reexported…
Browse files Browse the repository at this point in the history
… declarations (i.e. where both CollectorEntity.exported=true and AstSymbol.imported=true)
  • Loading branch information
pgonzal committed Dec 24, 2018
1 parent c0bed78 commit 5b870cc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
8 changes: 7 additions & 1 deletion apps/api-extractor/src/generators/ApiModelGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ export class ApiModelGenerator {
for (const entity of this._collector.entities) {
for (const astDeclaration of entity.astSymbol.astDeclarations) {
if (entity.exported) {
this._processDeclaration(astDeclaration, entity.nameForEmit, apiEntryPoint);
if (!entity.astSymbol.imported) {
this._processDeclaration(astDeclaration, entity.nameForEmit, apiEntryPoint);
} else {
// TODO: Figure out how to represent reexported definitions. Basically we need to introduce a new
// ApiItem subclass for "export alias", similar to a type alias, but representing declarations of the
// form "export { X } from 'external-package'". We can also use this to solve GitHub issue #950.
}
}
}
}
Expand Down
31 changes: 24 additions & 7 deletions apps/api-extractor/src/generators/ReviewFileGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DeclarationMetadata } from '../collector/DeclarationMetadata';
import { SymbolMetadata } from '../collector/SymbolMetadata';
import { ReleaseTag } from '../aedoc/ReleaseTag';
import { Text, InternalError } from '@microsoft/node-core-library';
import { AstImport } from '../analyzer/AstImport';

export class ReviewFileGenerator {
/**
Expand All @@ -35,15 +36,31 @@ export class ReviewFileGenerator {

for (const entity of collector.entities) {
if (entity.exported) {
// Emit all the declarations for this entry
for (const astDeclaration of entity.astSymbol.astDeclarations || []) {
if (!entity.astSymbol.astImport) {
// Emit all the declarations for this entry
for (const astDeclaration of entity.astSymbol.astDeclarations || []) {

output.append(ReviewFileGenerator._getAedocSynopsis(collector, astDeclaration));
output.append(ReviewFileGenerator._getAedocSynopsis(collector, astDeclaration));

const span: Span = new Span(astDeclaration.declaration);
ReviewFileGenerator._modifySpan(collector, span, entity, astDeclaration);
span.writeModifiedText(output);
output.append('\n\n');
const span: Span = new Span(astDeclaration.declaration);
ReviewFileGenerator._modifySpan(collector, span, entity, astDeclaration);
span.writeModifiedText(output);
output.append('\n\n');
}
} else {
// This definition is reexported from another package, so write it as an "export" line
// In general, we don't report on external packages; if that's important we assume API Extractor
// would be enabled for the upstream project. But see GitHub issue #896 for a possible exception.
const astImport: AstImport = entity.astSymbol.astImport;

if (astImport.exportName === '*') {
output.append(`export * as ${entity.nameForEmit}`);
} else if (entity.nameForEmit !== astImport.exportName) {
output.append(`export { ${astImport.exportName} as ${entity.nameForEmit} }`);
} else {
output.append(`export { ${astImport.exportName} }`);
}
output.append(` from '${astImport.modulePath}';\n`);
}
}
}
Expand Down

0 comments on commit 5b870cc

Please sign in to comment.