Compiler to convert Go language to JavaScript

The beta open source Joy compiler takes on the same task as GopherJS: to bring Go language approaches to JavaScript development

Thinkstock

Developers wanting to use the Google Go language, aka Golang, for web programming can try the beta open source Joy compiler, which promises—when it reaches production release—to turn Go code into JavaScript code.

With Joy, idiomatic Go code will be translated into JavaScript that will work in every browser (as ECMAScript 3 code, with ECMAScript 5 code on the roadmap as well), the open source project claims. It also means JavaScript developers will be able to use Go’s type system and tools. Joy project creator Matthew Mueller says the Go-to-JavaScript translation work is about 90 percent complete.

Translation to additional variations of JavaScript also is on the roadmap, as is compilation to the WebAssembly portable code format. Plans also call for Joy to support both the React JavaScript UI library and Preact, a React alternative. 

The Joy compiler will parse code into an abstract syntax tree (AST), index these processes, and create a dependency graph. The Go AST will then be translated into a JavaScript AST, whereupon JavaScript code is created.

Where to download the Joy compiler

You can dowload the beta Joy compiler from GitHub or by using this terminal command: curl -sfL https://raw.githubusercontent.com/matthewmueller/joy/master/install.sh | sh.

Other features in Joy

Other promised features of Joy include:

  • A simple macro system to integrate with existing JavaScript.
  • Use of Go static analysis tools to eliminate dead code.
  • Use of built-in headless Chrome, for running the Chrome browser in a headless environment, for running scripts.
  • Shipping of a minimal runtime when it is needed.
  • Typed, zero-cost DOM and virtual DOM packages.

GopherJS also brings Go to JavaScript

Joy is not the first attempt at Go-to-JavaScript compilation. The GopherJS compiler also compiles Go code to JavaScript, for running in browsers. GopherJS is more advanced than Joy in areas such as syntax translation.