@microsoft/api-extractor
Version:
Validate, document, and review the exported API for a TypeScript library
55 lines (53 loc) • 2.23 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 });
const AstItem_1 = require("./AstItem");
const AstParameter_1 = require("./AstParameter");
const TypeScriptHelpers_1 = require("../TypeScriptHelpers");
const PrettyPrinter_1 = require("../PrettyPrinter");
/**
* This class is part of the AstItem abstract syntax tree. It represents functions that are directly
* defined inside a package and are not member of classes, interfaces, or nested type literal expressions
*
* @see AstMethod for functions that are members of classes, interfaces, or nested type literal expressions
*/
class AstFunction extends AstItem_1.default {
constructor(options) {
super(options);
this.kind = AstItem_1.AstItemKind.Function;
const methodDeclaration = options.declaration;
// Parameters
if (methodDeclaration.parameters) {
this.params = [];
for (const param of methodDeclaration.parameters) {
const declarationSymbol = TypeScriptHelpers_1.default.tryGetSymbolForDeclaration(param);
const astParameter = new AstParameter_1.default({
context: this.context,
declaration: param,
declarationSymbol: declarationSymbol,
jsdocNode: param
});
this.innerItems.push(astParameter);
this.params.push(astParameter);
}
}
// Return type
if (methodDeclaration.type) {
this.returnType = methodDeclaration.type.getText();
}
else {
this.hasIncompleteTypes = true;
this.returnType = 'any';
}
}
/**
* Returns a text string such as "someName?: SomeTypeName;", or in the case of a type
* literal expression, returns a text string such as "someName?:".
*/
getDeclarationLine() {
return PrettyPrinter_1.default.getDeclarationSummary(this.declaration);
}
}
exports.default = AstFunction;
//# sourceMappingURL=AstFunction.js.map