Paul Krill
Editor at Large

Compiler to convert Go language to JavaScript

news
Dec 19, 20172 mins

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

Computerworld - Scary Tech [Slide-12] - Language translation systems run by big brother
Credit: 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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author