Fast TS transpiler removes types from a typescript file leaving readable javascript. Since generated javascript is line-by-line equivalent to the typescript source this allows to avoid using source maps while debugging.
npm install ftstfrom command line
node -r ftst filename.tstranspileModule(code, options, remove) - analogue of ts function with same name,
code - typescript code
options - specified compiler options
remove - if set to true generated output will be without commented out types
result = { outputText: outputText, diagnostics: diagnostics}outputText - resulting javascript code
diagnostics - array with syntax errors
var ftst = require("ftst/transpiler");
var options = {
compilerOptions: {
newLine: "lf",
downlevelIteration: true,
suppressExcessPropertyErrors: true,
module: ftst.ModuleKind.CommonJS,
removeComments: false,
target: ftst.ScriptTarget.ES2020,
noEmitHelpers: true,
preserveConstEnums: true,
noImplicitUseStrict: true
},
reportDiagnostics: true
};
let source = 'let decimal: number = 6;';
let result = ftst.transpileModule(source, options, true);transpile(code, options, remove) - shortcut function for transpileModule; returns only js code without diagnostics
Since the goal is to keep generated javascript readable, only Es2019, Es2020 and EsNext script targets are supported.
You need to make some preparations for using tests:
- Download latest version of ts sources from https://github.com/microsoft/TypeScript
- Create directory for typescripts tests, for example
tests, and copy content oftests\casesfrom ts sources to created dir - Use
prepare-tests.jsfrom CLI:node test/prepare-tests.js ./tests - Now your ready to use tests.
For main tests:
npm testFor Es2019 tests:
npm test test/test-es2019.jsFor TSX tests:
npm test test/test-tsx.js