ts-simple-ast
Version:
TypeScript compiler wrapper for static analysis and code manipulation.
73 lines (72 loc) • 3.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var typescript_1 = require("../../../typescript");
var statement_1 = require("../statement");
var callBaseGetStructure_1 = require("../callBaseGetStructure");
var callBaseSet_1 = require("../callBaseSet");
exports.ExportAssignmentBase = statement_1.Statement;
var ExportAssignment = /** @class */ (function (_super) {
tslib_1.__extends(ExportAssignment, _super);
function ExportAssignment() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Gets if this is an export equals assignment.
*
* If this is false, then it's `export default`.
*/
ExportAssignment.prototype.isExportEquals = function () {
return this.compilerNode.isExportEquals || false;
};
/**
* Sets if this is an export equals assignment or export default.
* @param value - Whether it should be an export equals assignment.
*/
ExportAssignment.prototype.setIsExportEquals = function (value) {
if (this.isExportEquals() === value)
return this;
if (value)
this.getFirstChildByKindOrThrow(typescript_1.SyntaxKind.DefaultKeyword).replaceWithText("=");
else
this.getFirstChildByKindOrThrow(typescript_1.SyntaxKind.EqualsToken).replaceWithText("default");
return this;
};
/**
* Gets the export assignment expression.
*/
ExportAssignment.prototype.getExpression = function () {
return this._getNodeFromCompilerNode(this.compilerNode.expression);
};
/**
* Sets the expression of the export assignment.
* @param textOrWriterFunction - Text or writer function to set as the export assignment expression.
*/
ExportAssignment.prototype.setExpression = function (textOrWriterFunction) {
this.getExpression().replaceWithText(textOrWriterFunction, this._getWriterWithQueuedChildIndentation());
return this;
};
/**
* Sets the node from a structure.
* @param structure - Structure to set the node with.
*/
ExportAssignment.prototype.set = function (structure) {
callBaseSet_1.callBaseSet(exports.ExportAssignmentBase.prototype, this, structure);
if (structure.expression != null)
this.setExpression(structure.expression);
if (structure.isExportEquals != null)
this.setIsExportEquals(structure.isExportEquals);
return this;
};
/**
* Gets the structure equivalent to this node.
*/
ExportAssignment.prototype.getStructure = function () {
return callBaseGetStructure_1.callBaseGetStructure(statement_1.Statement.prototype, this, {
expression: this.getExpression().getText(),
isExportEquals: this.isExportEquals()
});
};
return ExportAssignment;
}(exports.ExportAssignmentBase));
exports.ExportAssignment = ExportAssignment;