ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
27 lines (26 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var InsertionTextManipulator = /** @class */ (function () {
function InsertionTextManipulator(opts) {
this.opts = opts;
}
InsertionTextManipulator.prototype.getNewText = function (inputText) {
var _a = this.opts, insertPos = _a.insertPos, newText = _a.newText, _b = _a.replacingLength, replacingLength = _b === void 0 ? 0 : _b;
return inputText.substring(0, insertPos) + newText + inputText.substring(insertPos + replacingLength);
};
InsertionTextManipulator.prototype.getTextForError = function (newText) {
var startPos = Math.max(0, newText.lastIndexOf("\n", this.opts.insertPos) - 50);
var text = "";
var endPos = Math.min(newText.length, newText.indexOf("\n", this.opts.insertPos + this.opts.newText.length) + 50);
if (endPos === -1)
endPos = newText.length;
text += newText.substring(startPos, endPos);
if (startPos !== 0)
text = "..." + text;
if (endPos !== newText.length)
text += "...";
return text;
};
return InsertionTextManipulator;
}());
exports.InsertionTextManipulator = InsertionTextManipulator;