UNPKG

tstosc

Version:

A transpiler that convert TypeScript to SuperCollider's SCLang.

35 lines (29 loc) 1.2 kB
'use strict'; var ts = require('typescript'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var ts__default = /*#__PURE__*/_interopDefault(ts); const printer = ts__default.default.createPrinter({ newLine: ts__default.default.NewLineKind.LineFeed, omitTrailingSemicolon: true }); const fake_source_file = ts__default.default.createSourceFile("fake_source_file__tryFindSourceFile.ts", "", ts__default.default.ScriptTarget.Latest); function tryFindSourceFile(node) { if (ts__default.default.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__default.default.EmitHint.Unspecified, node, tryFindSourceFile(node)); } function printTSExpression(...node) { console.log( ...node.map((n) => convertToTSExpression(n)) ); } function getTypeOfTSNode(program, node) { return program.getTypeChecker().getTypeAtLocation(node); } exports.convertToTSExpression = convertToTSExpression; exports.getTypeOfTSNode = getTypeOfTSNode; exports.printTSExpression = printTSExpression;