private addExportDocs()

in typescript/src/processors/readTypeScriptModules/index.ts [88:149]


    private addExportDocs(docs: DocCollection, moduleDoc: ModuleDoc) {
      // Iterate through this module's exports and generate a doc for each
      moduleDoc.symbol.exportArray.forEach(exportSymbol => {

        // Ignore exports that match the configured regular expressions
        if (anyMatches(this.ignoreExportsRegexes, exportSymbol.name)) return;

        // If `exportSymbol.resolvedSymbol` is defined then the symbol has been "aliased":
        // * `exportSymbol.resolvedSymbol` holds the actual info about the symbol being exported
        // * `exportSymbol` is the "alias" symbol, which has the new name for the symbol being exported
        const resolvedExport = exportSymbol.resolvedSymbol || exportSymbol;
        const aliasSymbol = exportSymbol.resolvedSymbol ? exportSymbol : undefined;

        // If the resolved symbol contains no declarations then it is invalid (perhaps an abstract class?)
        // For the moment we are just going to ignore such exports (:scream:)
        // TODO: find a way of generating docs for them
        if (!resolvedExport.declarations) {
          this.log.info(`Export has no declarations: ${resolvedExport.name}`);
          return;
        }

        switch (getExportDocType(resolvedExport)) {
          case 'class':
            const classDoc = new ClassExportDoc(this.host, moduleDoc, resolvedExport, aliasSymbol);
            this.addMemberDocs(docs, classDoc.members);
            this.addMemberDocs(docs, classDoc.statics);
            if (classDoc.constructorDoc) this.addMemberDocs(docs, [classDoc.constructorDoc]);
            this.addExportDoc(docs, moduleDoc, classDoc);
            break;
          case 'interface':
            const interfaceDoc = new InterfaceExportDoc(this.host, moduleDoc, resolvedExport, aliasSymbol);
            this.addMemberDocs(docs, interfaceDoc.members);
            this.addExportDoc(docs, moduleDoc, interfaceDoc);
            break;
          case 'enum':
            const enumDoc = new EnumExportDoc(this.host, moduleDoc, resolvedExport, aliasSymbol);
            enumDoc.members.forEach(doc => docs.push(doc));
            this.addExportDoc(docs, moduleDoc, enumDoc);
            break;
          case 'const':
          case 'let':
          case 'var':
            this.addExportDoc(docs, moduleDoc, new ConstExportDoc(this.host, moduleDoc, resolvedExport, aliasSymbol));
            break;
          case 'type-alias':
            this.addExportDoc(docs, moduleDoc, new TypeAliasExportDoc(this.host, moduleDoc, resolvedExport, aliasSymbol));
            break;
          case 'function':
            const functionDoc = new FunctionExportDoc(this.host, moduleDoc, resolvedExport, aliasSymbol);
            this.addExportDoc(docs, moduleDoc, functionDoc);
            this.addParamDocs(docs, functionDoc.parameterDocs);
            functionDoc.overloads.forEach(overloadDoc => {
              docs.push(overloadDoc);
              this.addParamDocs(docs, overloadDoc.parameterDocs);
            });
            break;
          default:
            this.log.error(`Don't know how to create export document for ${resolvedExport.name}`);
            break;
        }
      });
    }