UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

87 lines (86 loc) 3.62 kB
"use strict"; var __extends = (this && this.__extends)/* istanbul ignore next */ || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var common_1 = require("./../common"); var manipulation_1 = require("./../../manipulation"); var base_1 = require("./../base"); var callBaseFill_1 = require("./../callBaseFill"); exports.ParameterDeclarationBase = base_1.QuestionTokenableNode(base_1.DecoratableNode(base_1.ScopeableNode(base_1.ReadonlyableNode(base_1.ModifierableNode(base_1.TypedNode(base_1.InitializerExpressionableNode(base_1.DeclarationNamedNode(common_1.Node)))))))); var ParameterDeclaration = /** @class */ (function (_super) { __extends(ParameterDeclaration, _super); function ParameterDeclaration() { return _super !== null && _super.apply(this, arguments) || this; } /** * Fills the node from a structure. * @param structure - Structure to fill. */ ParameterDeclaration.prototype.fill = function (structure) { callBaseFill_1.callBaseFill(exports.ParameterDeclarationBase.prototype, this, structure); if (structure.isRestParameter != null) this.setIsRestParameter(structure.isRestParameter); return this; }; /** * Gets the dot dot dot token (...) for a rest parameter. */ ParameterDeclaration.prototype.getDotDotDotToken = function () { return this.compilerNode.dotDotDotToken == null ? undefined : this.global.compilerFactory.getNodeFromCompilerNode(this.compilerNode.dotDotDotToken, this.sourceFile); }; /** * Gets if it's a rest parameter. */ ParameterDeclaration.prototype.isRestParameter = function () { return this.compilerNode.dotDotDotToken != null; }; /** * Gets if this is a parameter property. */ ParameterDeclaration.prototype.isParameterProperty = function () { return this.getScope() != null || this.isReadonly(); }; /** * Sets if it's a rest parameter. * @param value - Sets if it's a rest parameter or not. */ ParameterDeclaration.prototype.setIsRestParameter = function (value) { if (this.isRestParameter() === value) return this; if (value) { var nameNode = this.getNameNodeOrThrow(); manipulation_1.insertIntoParent({ insertPos: nameNode.getStart(), childIndex: nameNode.getChildIndex(), insertItemsCount: 1, parent: this, newText: "..." }); } else manipulation_1.removeChildren({ children: [this.getDotDotDotToken()] }); return this; }; /** * Gets if it's optional. */ ParameterDeclaration.prototype.isOptional = function () { return this.compilerNode.questionToken != null || this.isRestParameter() || this.hasInitializer(); }; /** * Remove this parameter. */ ParameterDeclaration.prototype.remove = function () { manipulation_1.removeCommaSeparatedChild(this); }; return ParameterDeclaration; }(exports.ParameterDeclarationBase)); exports.ParameterDeclaration = ParameterDeclaration;