mirror of
https://github.com/mdgriffith/elm-optimize-level-2.git
synced 2024-12-01 19:35:08 +03:00
31 lines
665 B
TypeScript
31 lines
665 B
TypeScript
import ts from 'typescript';
|
|
|
|
export function transformCode(
|
|
initialCode: string,
|
|
expectedCode: string,
|
|
transformer: ts.TransformerFactory<ts.SourceFile>
|
|
): {
|
|
actual: string;
|
|
expected: string;
|
|
} {
|
|
const source = ts.createSourceFile(
|
|
'elm.js',
|
|
initialCode,
|
|
ts.ScriptTarget.ES2018
|
|
);
|
|
|
|
const printer = ts.createPrinter();
|
|
|
|
const [output] = ts.transform(source, [transformer]).transformed;
|
|
|
|
const expectedOutput = printer.printFile(
|
|
ts.createSourceFile('elm.js', expectedCode, ts.ScriptTarget.ES2018)
|
|
);
|
|
|
|
const printedOutput = printer.printFile(output);
|
|
|
|
return {
|
|
actual: printedOutput,
|
|
expected: expectedOutput,
|
|
};
|
|
} |