Skip to content

Instantly share code, notes, and snippets.

@jthoms1
Created September 20, 2017 02:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jthoms1/5b36b64151ed0036d1f9413b72146c19 to your computer and use it in GitHub Desktop.
Save jthoms1/5b36b64151ed0036d1f9413b72146c19 to your computer and use it in GitHub Desktop.
Typescript transform test tool
function transformSourceFile(sourceText: string, transformers: ts.TransformerFactory<ts.SourceFile>[]) {
const transformed = ts.transform(ts.createSourceFile('source.ts', sourceText, ts.ScriptTarget.ES2015), transformers);
const printer = ts.createPrinter({ newLine: ts.NewLineKind.CarriageReturnLineFeed }, {
onEmitNode: transformed.emitNodeWithNotification,
substituteNode: transformed.substituteNode
});
const result = printer.printBundle(ts.createBundle(transformed.transformed));
transformed.dispose();
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment