Skip to content

Latest commit

 

History

History
88 lines (63 loc) · 3.01 KB

README.md

File metadata and controls

88 lines (63 loc) · 3.01 KB

ts2nim

Npm Version npm: total downloads Types license

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.

Motivation

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.

RoadMap

This project has two routes

  1. Generate nim js bridge through typescript type difinition file.
  2. Generate nim source code through typescript source file.

Todos

  • Inferring js type (object or others)
  • Inferring native type (eg. number is int or float)

Limitations

assemblyscript basics described well, share same theory.

Installation

npm i ts2nim or
yarn add ts2nim

Usage

ts2nim -i inputFileOrDir -o outFileOrDir

without param it will transpile current directory in place with extension .nim

Translation

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

Related Projects

mcclure/dts2nim

Projects use ts2nim

Add by you