UNPKG

tstosc

Version:

A transpiler that convert TypeScript to SuperCollider's SCLang.

27 lines (24 loc) 872 B
import ts from 'typescript'; const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed, omitTrailingSemicolon: true }); const fake_source_file = ts.createSourceFile("fake_source_file__tryFindSourceFile.ts", "", ts.ScriptTarget.Latest); function tryFindSourceFile(node) { if (ts.isSourceFile(node)) { return node; } if (node.parent != void 0 && node.parent != null) { return tryFindSourceFile(node.parent); } return fake_source_file; } function convertToTSExpression(node) { return printer.printNode(ts.EmitHint.Unspecified, node, tryFindSourceFile(node)); } function printTSExpression(...node) { console.log( ...node.map((n) => convertToTSExpression(n)) ); } function getTypeOfTSNode(program, node) { return program.getTypeChecker().getTypeAtLocation(node); } export { convertToTSExpression, getTypeOfTSNode, printTSExpression };