22
mints - lightweight typescript compiler (7.8kb)
mints is most lightweight typescript compiler ever.
npm install @mizchi/mints --save
yarn add @mizchi/mints
import { transformSync } from "@mizchi/mints";
const out = transformSync(`const x: number = 1;`);
console.log(out.code); // const x=1;
Today's web based code editors like vscode.dev includes typescript compiler but those are very heavy bundle size.
(compressed, no gzip)
I need lightweight compiler for casual case.
- interactive tutorial
- browser based authoring tool
I made mints-playground for this case.
- Lightweight
- Just drop type annotations like
:number
and transformenum
,constructor
'spublic/private/proctected
andjsx
. - Fast initial compile
- Support parallel compile
- All statements except those terminated by
}
require;
(expect prettier format) - mints tokenizer is unstable for RegExp Literal
/.../
yet.-
/
can not parse as RexExp (expect binary divider). use/[ ]...
-
/>
can not parse as RegExp (expect jsx) -
</
can not parse as RegExp (expect jsx)
-
- Not Support
with
namespace
decorator
(I tested prettier formatted code.)
I wrote parser-generator at first.
@mizchi/pargen
generates binary snapshot of parse rules. mints runtime load it.
$ yarn bench
mints_para is mints parallel version.
-------------- 2416chars
[tsc] 58ms
[esbuild] 14ms
[mints] 6ms
[mints_para] 12ms
-------------- 2981chars
[tsc] 14ms
[esbuild] 1ms
[mints] 9ms
[mints_para] 12ms
-------------- 5118chars
[tsc] 18ms
[esbuild] 1ms
[mints] 12ms
[mints_para] 22ms
-------------- 21153chars
[tsc] 55ms
[esbuild] 3ms
[mints] 59ms
[mints_para] 53ms
-------------- 18584chars
[tsc] 39ms
[esbuild] 2ms
[mints] 39ms
[mints_para] 32ms
-------------- 3844chars
[tsc] 12ms
[esbuild] 1ms
[mints] 9ms
[mints_para] 17ms
-------------- 38611chars
[tsc] 72ms
[esbuild] 3ms
[mints] 57ms
[mints_para] 45ms
-------------- 6935chars
[tsc] 13ms
[esbuild] 1ms
[mints] 13ms
[mints_para] 7ms
mints is fastest on first case that includes compiler ignition.
22