Skip to main content
Module

x/deno2node/src/deps.deno.ts>Node#transform

Compile your Deno project to run on Node.js.
Go to Latest
method Node.prototype.transform
import { Node } from "https://deno.land/x/deno2node@v1.7.1/src/deps.deno.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.

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.

const classDec = sourceFile.getClassOrThrow("MyClass");
classDec.transform(traversal => {
  const node = traversal.currentNode;
  return ts.updateClassDeclaration(node, undefined, undefined, ts.createIdentifier("MyUpdatedClass"), undefined, undefined, []);
});

Parameters

visitNode: (traversal: TransformTraversalControl) => ts.Node