Skip to content

auvred/typescript-ffi

Repository files navigation

typescript-ffi

Caution

Very experimental, very unsafe, very PoC

My take on bridging typescript-go with Node.js.

There is also official IPC-based API.

Supported

  • getProgram - program initialization
  • program.getSourceFile(filename) - AST transfer
  • program.getSymbolAtLocation(node) - symbol with flags and declarations in AST
  • program.getTypeAtLocation(node) - type with flags, symbol and type constituents (for unions and intersections)

Approach

The addon is written using Node-API (due to ABI Stability).

In contrast with Oxlint JS Plugins and Deno Lint Plugins which both rely on JS-side lazy deserialization of raw AST stored in binary form, I've decided to explore the route of eager deserialization. I believe that real-world lint rules use more than a few AST node types and touch a significant portion of the entire AST, thus discarding the benefit of lazy deserialization.

The encoder generator, based on typescript-go's structs shapes and sizes, generates a C-based encoder which understands the Go memory layout (including dynamically typed fields stored as Go interfaces) and translates the entire SourceFile AST to napi_value without making any CGO calls.

Building

Prerequisites:

  • Go
  • C compiler (tested with GCC)
git submodule update --init
make build

License

MIT

About

PoC: typescript-go addon for Node.js

Resources

License

Stars

Watchers

Forks