elm-optimize-level-2/test/removedUnusedLocals.test.ts

41 lines
938 B
TypeScript
Raw Normal View History

import ts from 'typescript';
2020-08-17 00:23:16 +03:00
import { createRemoveUnusedLocalsTransform } from '../src/transforms/removeUnusedLocals';
test('it can process nested calls of A2 with non identifiers as the first arg ', () => {
const initialCode = `
(function (){
function f () {return 2;}
const f2 = () => 1 + f();
const test = 1 + 2, bla="bla";
console.log(test);
})()
`;
const expectedOutputCode = `
(function (){
const test = 1 + 2;
console.log(test);
})()
`;
const source = ts.createSourceFile(
'elm.js',
initialCode,
ts.ScriptTarget.ES2018
);
const printer = ts.createPrinter();
const [output] = ts.transform(source, [
createRemoveUnusedLocalsTransform(),
]).transformed;
const expectedOutput = printer.printFile(
ts.createSourceFile('elm.js', expectedOutputCode, ts.ScriptTarget.ES2018)
);
const printedOutput = printer.printFile(output);
expect(printedOutput).toBe(expectedOutput);
});