UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for static analysis and code manipulation.

53 lines (52 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var errors = require("../../../errors"); var callBaseGetStructure_1 = require("../callBaseGetStructure"); var callBaseSet_1 = require("../callBaseSet"); var expression_1 = require("../expression"); var base_1 = require("./base"); exports.JsxSelfClosingElementBase = base_1.JsxAttributedNode(base_1.JsxTagNamedNode(expression_1.PrimaryExpression)); var JsxSelfClosingElement = /** @class */ (function (_super) { tslib_1.__extends(JsxSelfClosingElement, _super); function JsxSelfClosingElement() { return _super !== null && _super.apply(this, arguments) || this; } /** * Sets the node from a structure. * @param structure - Structure to set the node with. */ JsxSelfClosingElement.prototype.set = function (structure) { callBaseSet_1.callBaseSet(exports.JsxSelfClosingElementBase.prototype, this, structure); if (structure.attributes != null) { this.getAttributes().forEach(function (a) { return a.remove(); }); this.addAttributes(structure.attributes); } if (structure.isSelfClosing === false) throw new errors.NotImplementedError("Changing a JsxSelfClosingElement to be non-self closing is not implemented. Please open an issue if you need this."); if (structure.children != null) throw new errors.NotImplementedError("Changing a JsxSelfClosingElement to be non-self closing is not implemented. Please open an issue if you need this."); if (structure.bodyText != null) throw new errors.NotImplementedError("Changing a JsxSelfClosingElement to be non-self closing is not implemented. Please open an issue if you need this."); if (structure.name != null) this.getTagNameNode().replaceWithText(structure.name); return this; }; /** * Gets the structure equivalent to this node. */ JsxSelfClosingElement.prototype.getStructure = function () { var structure = callBaseGetStructure_1.callBaseGetStructure(exports.JsxSelfClosingElementBase.prototype, this, { name: this.getTagNameNode().getText(), attributes: this.getAttributes().map(function (a) { return a.getStructure(); }), children: undefined, isSelfClosing: true, bodyText: undefined }); delete structure.children; delete structure.bodyText; return structure; }; return JsxSelfClosingElement; }(exports.JsxSelfClosingElementBase)); exports.JsxSelfClosingElement = JsxSelfClosingElement;