ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
25 lines (24 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var ts = require("typescript");
var NodeHandlerHelper = /** @class */ (function () {
function NodeHandlerHelper(compilerFactory) {
this.compilerFactory = compilerFactory;
}
NodeHandlerHelper.prototype.handleForValues = function (handler, currentNode, newNode) {
if (this.compilerFactory.hasCompilerNode(currentNode))
handler.handleNode(this.compilerFactory.getExistingCompilerNode(currentNode), newNode);
else if (currentNode.kind === ts.SyntaxKind.SyntaxList) {
// always handle syntax lists because their children might be in the cache
// todo: pass this in for performance reasons
var sourceFile = this.compilerFactory.getExistingCompilerNode(currentNode.getSourceFile());
handler.handleNode(this.compilerFactory.getNodeFromCompilerNode(currentNode, sourceFile), newNode);
}
};
NodeHandlerHelper.prototype.forgetNodeIfNecessary = function (currentNode) {
if (this.compilerFactory.hasCompilerNode(currentNode))
this.compilerFactory.getExistingCompilerNode(currentNode).forget();
};
return NodeHandlerHelper;
}());
exports.NodeHandlerHelper = NodeHandlerHelper;