UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

30 lines (28 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const errors = require("./../../errors"); const callBaseFill_1 = require("./../callBaseFill"); const setBodyTextForNode_1 = require("./helpers/setBodyTextForNode"); function BodiedNode(Base) { return class extends Base { getBody() { const body = this.compilerNode.body; if (body == null) throw new errors.InvalidOperationError("Bodied node should have a body."); return this.global.compilerFactory.getNodeFromCompilerNode(body, this.sourceFile); } setBodyText(textOrWriterFunction) { const body = this.getBody(); setBodyTextForNode_1.setBodyTextForNode(body, textOrWriterFunction); return this; } fill(structure) { callBaseFill_1.callBaseFill(Base.prototype, this, structure); if (structure.bodyText != null) this.setBodyText(structure.bodyText); return this; } }; } exports.BodiedNode = BodiedNode; //# sourceMappingURL=BodiedNode.js.map