import { Node } from "https://deno.land/x/fresh@1.2.0/src/dev/deps.ts";
Transforms the node using the compiler api nodes and functions and returns the node that was transformed (experimental).
WARNING: This will forget descendants of transformed nodes and potentially this node.
Examples
Increments all the numeric literals in a source file.
Increments all the numeric literals in a source file.
sourceFile.transform(traversal => {
const node = traversal.visitChildren(); // recommend always visiting the children first (post order)
if (ts.isNumericLiteral(node))
return ts.createNumericLiteral((parseInt(node.text, 10) + 1).toString());
return node;
});
Updates the class declaration node without visiting the children.
Updates the class declaration node without visiting the children.
const classDec = sourceFile.getClassOrThrow("MyClass");
classDec.transform(traversal => {
const node = traversal.currentNode;
return ts.updateClassDeclaration(node, undefined, undefined, ts.createIdentifier("MyUpdatedClass"), undefined, undefined, []);
});