Caution
Very experimental, very unsafe, very PoC
My take on bridging typescript-go with Node.js.
There is also official IPC-based API.
getProgram- program initializationprogram.getSourceFile(filename)- AST transferprogram.getSymbolAtLocation(node)- symbol with flags and declarations in ASTprogram.getTypeAtLocation(node)- type with flags, symbol and type constituents (for unions and intersections)
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.
Prerequisites:
- Go
- C compiler (tested with GCC)
git submodule update --init
make build