ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
24 lines (23 loc) • 950 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tree_1 = require("./../tree");
var getNewReplacementSourceFile_1 = require("./../getNewReplacementSourceFile");
/**
* Replaces a node text while possibly creating new child nodes.
*/
function replaceTextPossiblyCreatingChildNodes(opts) {
var replacePos = opts.replacePos, replacingLength = opts.replacingLength, newText = opts.newText, parent = opts.parent;
var tempSourceFile = getNewReplacementSourceFile_1.getNewReplacementSourceFile({
sourceFile: parent.getSourceFile(),
insertPos: replacePos,
replacingLength: replacingLength,
newText: newText
});
tree_1.replaceTreeWithRange({
parent: parent,
replacementSourceFile: tempSourceFile,
start: replacePos,
end: replacePos + newText.length
});
}
exports.replaceTextPossiblyCreatingChildNodes = replaceTextPossiblyCreatingChildNodes;