import { transform } from "../src/index" ; import ts from "typescript" ; import fs from "fs" ; import path from "path" ; import { printPerfResult } from "@mizchi/pargen/src" ; const code0 = fs . readFileSync ( path . join ( __dirname , "cases/example0.ts" ) , "utf-8" ) ; const code1 = fs . readFileSync ( path . join ( __dirname , "cases/example1.ts" ) , "utf-8" ) ; const code2 = fs . readFileSync ( path . join ( __dirname , "cases/example2.ts" ) , "utf-8" ) ; const code3 = fs . readFileSync ( path . join ( __dirname , "cases/example3.ts" ) , "utf-8" ) ; const code4 = fs . readFileSync ( path . join ( __dirname , "cases/example4.ts" ) , "utf-8" ) ; const code5 = fs . readFileSync ( path . join ( __dirname , "cases/example5.ts" ) , "utf-8" ) ; function compileTsc ( input ) { return ts . transpileModule ( input , { compilerOptions : { module : ts . ModuleKind . ESNext , target : ts . ScriptTarget . Latest , } , } ) . outputText ; } function compileMints ( input ) { const out = transform ( input ) ; if ( out . error ) { throw out ; } return out . result as string ; } export function main ( ) { const compilers = [ compileTsc , compileMints ] ; const targets = [ code0 , code1 , code2 , code3 , ] ; for ( const code of targets ) { for ( const compiler of compilers ) { const N = 2 ; for ( let i = 0 ; i < N ; i ++ ) { const now = Date . now ( ) ; const out = compiler ( code ) ; console . log ( compiler . name , `[${ i }]` , Date . now ( ) - now ) ; if ( i === N - 1 ) { } } if ( process . env . NODE_ENV === "perf" && compiler === compileMints ) { printPerfResult ( ) ; } } } } main ( ) ;