@@ -10,8 +10,14 @@ import { WorkingPackage } from '../collector/WorkingPackage';
1010import { AstModule } from './AstModule' ;
1111import { AstImport } from './AstImport' ;
1212
13- export type ResultOrError < T > = Error | T ;
14-
13+ /**
14+ * This resolves a TSDoc declaration reference by walking the `AstSymbolTable` compiler state.
15+ *
16+ * @remarks
17+ *
18+ * This class is analogous to `ModelReferenceResolver` from the `@microsoft/api-extractor-model` project,
19+ * which resolves declaration references by walking the hierarchy loaded from an .api.json file.
20+ */
1521export class AstReferenceResolver {
1622 private readonly _astSymbolTable : AstSymbolTable ;
1723 private readonly _workingPackage : WorkingPackage ;
@@ -21,7 +27,7 @@ export class AstReferenceResolver {
2127 this . _workingPackage = workingPackage ;
2228 }
2329
24- public resolve ( declarationReference : tsdoc . DocDeclarationReference ) : ResultOrError < AstDeclaration > {
30+ public resolve ( declarationReference : tsdoc . DocDeclarationReference ) : AstDeclaration | Error {
2531 // Is it referring to the working package?
2632 if ( declarationReference . packageName !== undefined
2733 && declarationReference . packageName !== this . _workingPackage . name ) {
@@ -42,7 +48,7 @@ export class AstReferenceResolver {
4248
4349 const rootMemberReference : tsdoc . DocMemberReference = declarationReference . memberReferences [ 0 ] ;
4450
45- const exportName : ResultOrError < string > = this . _getMemberReferenceIdentifier ( rootMemberReference ) ;
51+ const exportName : string | Error = this . _getMemberReferenceIdentifier ( rootMemberReference ) ;
4652 if ( exportName instanceof Error ) {
4753 return exportName ;
4854 }
@@ -58,7 +64,7 @@ export class AstReferenceResolver {
5864 return new Error ( 'Reexported declarations are not supported' ) ;
5965 }
6066
61- let currentDeclaration : ResultOrError < AstDeclaration > = this . _selectDeclaration ( rootAstEntity . astDeclarations ,
67+ let currentDeclaration : AstDeclaration | Error = this . _selectDeclaration ( rootAstEntity . astDeclarations ,
6268 rootMemberReference , rootAstEntity . localName ) ;
6369
6470 if ( currentDeclaration instanceof Error ) {
@@ -68,7 +74,7 @@ export class AstReferenceResolver {
6874 for ( let index : number = 1 ; index < declarationReference . memberReferences . length ; ++ index ) {
6975 const memberReference : tsdoc . DocMemberReference = declarationReference . memberReferences [ index ] ;
7076
71- const memberName : ResultOrError < string > = this . _getMemberReferenceIdentifier ( memberReference ) ;
77+ const memberName : string | Error = this . _getMemberReferenceIdentifier ( memberReference ) ;
7278 if ( memberName instanceof Error ) {
7379 return memberName ;
7480 }
@@ -78,7 +84,7 @@ export class AstReferenceResolver {
7884 return new Error ( `No member was found with name "${ memberName } "` ) ;
7985 }
8086
81- const selectedDeclaration : ResultOrError < AstDeclaration > = this . _selectDeclaration ( matchingChildren ,
87+ const selectedDeclaration : AstDeclaration | Error = this . _selectDeclaration ( matchingChildren ,
8288 memberReference , memberName ) ;
8389
8490 if ( selectedDeclaration instanceof Error ) {
@@ -91,7 +97,7 @@ export class AstReferenceResolver {
9197 return currentDeclaration ;
9298 }
9399
94- private _getMemberReferenceIdentifier ( memberReference : tsdoc . DocMemberReference ) : ResultOrError < string > {
100+ private _getMemberReferenceIdentifier ( memberReference : tsdoc . DocMemberReference ) : string | Error {
95101 if ( memberReference . memberSymbol !== undefined ) {
96102 return new Error ( 'ECMAScript symbol selectors are not supported' ) ;
97103 }
@@ -102,7 +108,7 @@ export class AstReferenceResolver {
102108 }
103109
104110 private _selectDeclaration ( astDeclarations : ReadonlyArray < AstDeclaration > ,
105- memberReference : tsdoc . DocMemberReference , astSymbolName : string ) : ResultOrError < AstDeclaration > {
111+ memberReference : tsdoc . DocMemberReference , astSymbolName : string ) : AstDeclaration | Error {
106112
107113 if ( memberReference . selector === undefined ) {
108114 if ( astDeclarations . length === 1 ) {
0 commit comments