ts-simple-ast
Version:
TypeScript compiler wrapper for static analysis and code manipulation.
63 lines (62 loc) • 2.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var manipulation_1 = require("../../../manipulation");
var errors = require("../../../errors");
var callBaseSet_1 = require("../callBaseSet");
var callBaseGetStructure_1 = require("../callBaseGetStructure");
var common_1 = require("../common");
exports.JsxSpreadAttributeBase = common_1.Node;
var JsxSpreadAttribute = /** @class */ (function (_super) {
tslib_1.__extends(JsxSpreadAttribute, _super);
function JsxSpreadAttribute() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Gets the JSX spread attribute's expression.
*/
JsxSpreadAttribute.prototype.getExpression = function () {
return this._getNodeFromCompilerNode(this.compilerNode.expression);
};
/**
* Sets the expression.
* @param textOrWriterFunction - Text to set the expression with.
*/
JsxSpreadAttribute.prototype.setExpression = function (textOrWriterFunction) {
this.getExpression().replaceWithText(textOrWriterFunction);
return this;
};
/**
* Removes the JSX spread attribute.
*/
JsxSpreadAttribute.prototype.remove = function () {
manipulation_1.removeChildren({
children: [this],
removePrecedingNewLines: true,
removePrecedingSpaces: true
});
};
/**
* Sets the node from a structure.
* @param structure - Structure to set the node with.
*/
JsxSpreadAttribute.prototype.set = function (structure) {
callBaseSet_1.callBaseSet(exports.JsxSpreadAttributeBase.prototype, this, structure);
if (structure.isSpreadAttribute === false)
throw new errors.NotImplementedError("Not implemented ability to convert a spread attribute to a regular attribute. Open up an issue if you need this.");
if (structure.expression != null)
this.setExpression(structure.expression);
return this;
};
/**
* Gets the structure equivalent to this node.
*/
JsxSpreadAttribute.prototype.getStructure = function () {
return callBaseGetStructure_1.callBaseGetStructure(exports.JsxSpreadAttributeBase.prototype, this, {
isSpreadAttribute: true,
expression: this.getExpression().getText()
});
};
return JsxSpreadAttribute;
}(exports.JsxSpreadAttributeBase));
exports.JsxSpreadAttribute = JsxSpreadAttribute;