Skip to content

Instantly share code, notes, and snippets.

@roytouw7
Created August 20, 2020 12:37
Show Gist options
  • Save roytouw7/01bb087ea461c809c3fae0f188cbfdad to your computer and use it in GitHub Desktop.
Save roytouw7/01bb087ea461c809c3fae0f188cbfdad to your computer and use it in GitHub Desktop.
// Recursively visit every node in sourcefile.
const visitSourceFile = (sourceFile: ts.SourceFile, context: ts.TransformationContext): ts.SourceFile => {
const imports = new Set<RxJSPart>();
const visitNodes = (node: ts.Node): ts.Node => {
const [dispatchedNode, classification] = dispatch(node);
imports.add(classification);
return ts.visitEachChild(dispatchedNode, visitNodes, context);
};
const root = visitNodes(sourceFile) as ts.SourceFile;
return addImports(root, imports)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment