@microsoft/api-extractor
Version:
Validate, document, and review the exported API for a TypeScript library
55 lines (53 loc) • 2.43 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
/* tslint:disable:no-bitwise */
const ts = require("typescript");
const AstItemContainer_1 = require("./AstItemContainer");
const AstStructuredType_1 = require("./AstStructuredType");
const AstEnum_1 = require("./AstEnum");
const AstFunction_1 = require("./AstFunction");
/**
* This is an abstract base class for AstPackage and AstNamespace.
*/
class AstModule extends AstItemContainer_1.default {
processModuleExport(exportSymbol) {
const followedSymbol = this.followAliases(exportSymbol);
if (!followedSymbol.declarations) {
// This is an API Extractor bug, but it could happen e.g. if we upgrade to a new
// version of the TypeScript compiler that introduces new AST variations that we
// haven't tested before.
this.reportWarning(`Definition with no declarations: ${exportSymbol.name}`);
return;
}
for (const declaration of followedSymbol.declarations) {
const options = {
context: this.context,
declaration,
declarationSymbol: followedSymbol,
jsdocNode: declaration,
exportSymbol
};
if (followedSymbol.flags & (ts.SymbolFlags.Class | ts.SymbolFlags.Interface)) {
this.addMemberItem(new AstStructuredType_1.default(options));
}
else if (followedSymbol.flags & ts.SymbolFlags.ValueModule) {
this.addMemberItem(new AstNamespace_1.default(options)); // tslint:disable-line:no-use-before-declare
}
else if (followedSymbol.flags & ts.SymbolFlags.Function) {
this.addMemberItem(new AstFunction_1.default(options));
}
else if (followedSymbol.flags & ts.SymbolFlags.Enum) {
this.addMemberItem(new AstEnum_1.default(options));
}
else {
this.reportWarning(`Unsupported export: ${exportSymbol.name}`);
}
}
}
}
exports.default = AstModule;
// This is defer imported to break the circular dependency
const AstNamespace_1 = require("./AstNamespace");
//# sourceMappingURL=AstModule.js.map