Skip to content

Tech Detail Design

Sam Cao edited this page Jun 17, 2023 · 19 revisions

Architecture

There is a Node.js runtime embedded in Jaspiler. It hosts multiple Babel flavored transform plugins that transform the Java code at AST level. Thanks to Javet (an awesome way of embedding Node.js and V8 in Java), Jaspiler is able to run JavaScript code easily.

jaspiler design overview

With the help of Javet, Jaspiler injects a global namespace jaspiler that enables the transform, AST manipulation, etc.

Why JavaScript?

Though Jaspiler API is open if the applications prefer directly referencing the Jaspiler binary, it's quite inconvienent to write plugins in Java because Java applications have to go through the compilation, dependency resolution, runtime version mismatch, ...etc. That seriously slows down development.

Babel provides a much better experience in terms of transforming JavaScript code. So, why not borrow the similar experience in manipulating the Java AST in JavaScript? With Jaspiler, it is from write - compile - deploy - run to write - run with much better productivity and flexibility. Also, with the rich Node.js ecosystem, the JavaScript is able to access file system, network, basically not only do whatever a normal Node.js application can do, but also access the Java compiler exposed by Jaspiler.

How does Jaspiler Get the AST?

Jaspiler has its own implementation on the official JavaCompiler built-in with JDK. So, the AST is the same as what javac sees with 100% compatibility. This design is top of the line compared to other third-party implementations.

Clone this wiki locally