ts-simple-ast
Version:
TypeScript compiler wrapper for static analysis and code manipulation.
28 lines (27 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var RenameLocationTextManipulator = /** @class */ (function () {
function RenameLocationTextManipulator(renameLocations, newName) {
this.renameLocations = renameLocations;
this.newName = newName;
}
RenameLocationTextManipulator.prototype.getNewText = function (inputText) {
// get the rename locations in reverse order
var renameLocations = this.renameLocations.map(function (l) { return l.getTextSpan(); }).sort(function (a, b) { return b.getStart() - a.getStart(); });
var currentPos = inputText.length;
var result = "";
for (var i = 0; i < renameLocations.length; i++) {
var textSpan = renameLocations[i];
result = this.newName + inputText.substring(textSpan.getEnd(), currentPos) + result;
currentPos = textSpan.getStart();
}
return inputText.substring(0, currentPos) + result;
};
RenameLocationTextManipulator.prototype.getTextForError = function (newText) {
if (this.renameLocations.length === 0)
return newText;
return "..." + newText.substring(this.renameLocations[0].getTextSpan().getStart());
};
return RenameLocationTextManipulator;
}());
exports.RenameLocationTextManipulator = RenameLocationTextManipulator;