import ts from "typescript" ; import { DevelopmentError } from "../Exception" ; import * as Factory from "./factory" ; import { CreateFunction , traverse } from "./traverse" ; export * as Utils from "./utils" ; export { CreateFunction , Factory } ; export type TransformerFactory < T extends ts . Node > = ts . TransformerFactory < T > ; export const convertAstToTypeScriptCode = ( sourceFile ) : string => { const printer = ts . createPrinter ( ) ; return printer . printFile ( sourceFile ) ; } ; export const generate = ( createFunction ) : string => { const source = ts . createSourceFile ( "" , "" , ts . ScriptTarget . ESNext ) ; const transformers = [ traverse ( createFunction ) ] ; const result = ts . transform ( source , transformers ) ; result . dispose ( ) ; if ( result . transformed . length > 1 ) { throw new DevelopmentError ( "Invalid length" ) ; } return convertAstToTypeScriptCode ( result . transformed [ 0 ] ) ; } ;