UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

75 lines (73 loc) 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ts = require("typescript"); const common_1 = require("./../common"); const manipulation_1 = require("./../../manipulation"); const getStructureFuncs = require("./../../manipulation/getStructureFunctions"); const base_1 = require("./../base"); const statement_1 = require("./../statement"); const namespace_1 = require("./../namespace"); const callBaseFill_1 = require("./../callBaseFill"); const FunctionLikeDeclaration_1 = require("./FunctionLikeDeclaration"); const OverloadableNode_1 = require("./OverloadableNode"); exports.FunctionDeclarationBase = base_1.TextInsertableNode(OverloadableNode_1.OverloadableNode(base_1.BodyableNode(base_1.AsyncableNode(base_1.GeneratorableNode(FunctionLikeDeclaration_1.FunctionLikeDeclaration(statement_1.StatementedNode(base_1.AmbientableNode(namespace_1.NamespaceChildableNode(base_1.ExportableNode(base_1.ModifierableNode(base_1.NamedNode(common_1.Node)))))))))))); class FunctionDeclaration extends exports.FunctionDeclarationBase { /** * Fills the node from a structure. * @param structure - Structure to fill. */ fill(structure) { callBaseFill_1.callBaseFill(exports.FunctionDeclarationBase.prototype, this, structure); if (structure.overloads != null && structure.overloads.length > 0) this.addOverloads(structure.overloads); return this; } /** * Adds a function overload. * @param structure - Structure of the overload. */ addOverload(structure) { return this.addOverloads([structure])[0]; } /** * Adds function overloads. * @param structures - Structures of the overloads. */ addOverloads(structures) { return this.insertOverloads(this.getOverloads().length, structures); } /** * Inserts a function overload. * @param index - Index to insert. * @param structure - Structure of the overload. */ insertOverload(index, structure) { return this.insertOverloads(index, [structure])[0]; } /** * Inserts function overloads. * @param index - Index to insert. * @param structure - Structures of the overloads. */ insertOverloads(index, structures) { const thisName = this.getName(); const childCodes = structures.map(structure => `function ${thisName}();`); return OverloadableNode_1.insertOverloads({ node: this, index, structures, childCodes, getThisStructure: getStructureFuncs.fromFunctionDeclarationOverload, fillNodeFromStructure: (node, structure) => node.fill(structure), expectedSyntaxKind: ts.SyntaxKind.FunctionDeclaration }); } /** * Removes this function declaration. */ remove() { manipulation_1.removeOverloadableStatementedNodeChild(this); } } exports.FunctionDeclaration = FunctionDeclaration; //# sourceMappingURL=FunctionDeclaration.js.map