ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
74 lines (72 loc) • 2.66 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("./../common");
const manipulation_1 = require("./../../manipulation");
const base_1 = require("./../base");
const 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))))))));
class ParameterDeclaration extends exports.ParameterDeclarationBase {
/**
* Fills the node from a structure.
* @param structure - Structure to fill.
*/
fill(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.
*/
getDotDotDotToken() {
return this.compilerNode.dotDotDotToken == null ? undefined : this.global.compilerFactory.getNodeFromCompilerNode(this.compilerNode.dotDotDotToken, this.sourceFile);
}
/**
* Gets if it's a rest parameter.
*/
isRestParameter() {
return this.compilerNode.dotDotDotToken != null;
}
/**
* Gets if this is a parameter property.
*/
isParameterProperty() {
return this.getScope() != null || this.isReadonly();
}
/**
* Sets if it's a rest parameter.
* @param value - Sets if it's a rest parameter or not.
*/
setIsRestParameter(value) {
if (this.isRestParameter() === value)
return this;
if (value) {
const nameIdentifier = this.getNameIdentifierOrThrow();
manipulation_1.insertIntoParent({
insertPos: nameIdentifier.getStart(),
childIndex: nameIdentifier.getChildIndex(),
insertItemsCount: 1,
parent: this,
newText: "..."
});
}
else
manipulation_1.removeChildren({ children: [this.getDotDotDotToken()] });
return this;
}
/**
* Gets if it's optional.
*/
isOptional() {
return this.compilerNode.questionToken != null || this.isRestParameter() || this.hasInitializer();
}
/**
* Remove this parameter.
*/
remove() {
manipulation_1.removeCommaSeparatedChild(this);
}
}
exports.ParameterDeclaration = ParameterDeclaration;
//# sourceMappingURL=ParameterDeclaration.js.map