ts-simple-ast
Version:
TypeScript compiler wrapper for static analysis and code manipulation.
19 lines (18 loc) • 905 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var errors = require("../../errors");
function doManipulation(sourceFile, textManipulator, nodeHandler, newFilePath) {
sourceFile._firePreModified();
var newFileText = textManipulator.getNewText(sourceFile.getFullText());
try {
var replacementSourceFile = sourceFile._context.compilerFactory.createCompilerSourceFileFromText(newFilePath || sourceFile.getFilePath(), newFileText);
nodeHandler.handleNode(sourceFile, replacementSourceFile, replacementSourceFile);
}
catch (err) {
throw new errors.InvalidOperationError(err.message + "\n" +
"-- Details --\n" +
("Path: " + sourceFile.getFilePath() + "\n") +
("Text: " + JSON.stringify(textManipulator.getTextForError(newFileText))));
}
}
exports.doManipulation = doManipulation;