ts-simple-ast
Version:
TypeScript compiler wrapper for static analysis and code manipulation.
43 lines (42 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var errors = require("../../../errors");
var callBaseSet_1 = require("../callBaseSet");
var helpers_1 = require("./helpers");
var callBaseGetStructure_1 = require("../callBaseGetStructure");
function BodiedNode(Base) {
return /** @class */ (function (_super) {
tslib_1.__extends(class_1, _super);
function class_1() {
return _super !== null && _super.apply(this, arguments) || this;
}
class_1.prototype.getBody = function () {
var body = this.compilerNode.body;
if (body == null)
throw new errors.InvalidOperationError("Bodied node should have a body.");
return this._getNodeFromCompilerNode(body);
};
class_1.prototype.setBodyText = function (textOrWriterFunction) {
var body = this.getBody();
helpers_1.setBodyTextForNode(body, textOrWriterFunction);
return this;
};
class_1.prototype.set = function (structure) {
callBaseSet_1.callBaseSet(Base.prototype, this, structure);
if (structure.bodyText != null)
this.setBodyText(structure.bodyText);
return this;
};
class_1.prototype.getBodyText = function () {
return helpers_1.getBodyTextWithoutLeadingIndentation(this.getBody());
};
class_1.prototype.getStructure = function () {
return callBaseGetStructure_1.callBaseGetStructure(Base.prototype, this, {
bodyText: this.getBodyText()
});
};
return class_1;
}(Base));
}
exports.BodiedNode = BodiedNode;