Typescript to Nim transpiler
It also can translate js code with the Nim type auto
as typescript-estree
compatible with the js estree.
It identified the .d.ts
file if the ast node is TSMethodSignature
it will add importcpp
pragma to translated proc
, so it could be used as a wrapper generator.
Transpile nodejs modules, write in Typescript and transpile it to Nim, expand the Nim-Javascript backend ecosystem and so on.
Current goal is translating Typescript syntax into valid and pretty looking nim code. you may manually modify nim sources after translation. it just translate source code exclude dependency,even modules in nodejs std.
demo transpiled project:
vscode-uri
It can be easy to translate library processes like string manipulation, images, bytes and all these things.
This project has two routes
- Generate nim js bridge through typescript type difinition file.
- Generate nim source code through typescript source file.
- Inferring js type (object or others)
- Inferring native type (eg. number is int or float)
assemblyscript basics described well, share same theory.
npm i ts2nim
or
yarn add ts2nim
ts2nim -i inputFileOrDir -o outFileOrDir
without param it will transpile current directory in place with extension .nim
origin | to | description |
---|---|---|
number | float | |
boolean | bool | |
interface,type,class | type | |
Example() | newExample() | constructor for a class |
let,var,const | var | const no-object -> const,others var |
this | self | |
null,undefinded | nil | |
optinal param | none(T) | options module |
T|null,T|undefinded | T | ref type |
RestElement param | openArray[T] | |
switch | case of | |
Array | seq | |
StringTemplate | fmt | strformat module |
do while | doWhile | doWhile template |
raise new T() | raise newException(T) | |
.length | .len | |
.push | .add | |
fs.readFileSync | readFile | os module |
path.join | / | os module |
.some | .any | sequtils module |
.sort | .sorted | algorithm module |
async | {.async.} | asyncdispatch or asyncjs module |
=== | == | |
!== | != | |
&& | and | |
|| | or | |
! | not | |
& or | depends on a literal string or number found | |
delete | assign to nil | |
extends A,B | ref object of A,B | Multiple Inheritance not supported in Nim |
Add by you