#2894 Modernizing the Fantom JavaScript Implementation

matthew Wed 19 Jul 2023

We would like to publicly announce a new project to modernize the JavaScript implementation in Fantom. The original implementation of the sys pod and JS compiler is almost 15 years old now. The language has come a long way since 2009 and this provides an opportunity to revisit the design and performance of the JavaScript code in Fantom. The browser and JS runtime (e.g. NodeJS) are important targets for Fantom code and we find that developers increasingly want to work with Fantom APIs in native JS environments like TypeScript and Node.

The project currently exists as a fork of the main Fantom repo in GitHub.


There are several goals for this project, which we will briefly outline here. A "living" design document which goes into more detail can be found in the repo at design.md

  1. Use modern ECMAScript (ES) conventions
    1. Package code as ECMAScript modules (ESM)
    2. Convert all native JS implementations to use JS class syntax
  2. Make generated code more friendly/intuitive to use in native JS environments
    1. All Fantom APIs that use closures, now use native javascript functions/closures
    2. Formalize some naming and implementation conventions for the public API of a class
  3. Make it easier to use generated JS in TypeScript by emitting TypeScript declaration files (d.ts).
  4. Look for opportunities to improve the performance of our JavaScript implementation. For example, refactor Buf.js to use TypedArrays.

At this time we would like to invite the community to review the design and provide feedback on the implementation. The initial implementation is complete with the following features:

  1. All the native Fantom code has been ported to the ES format
  2. We have a new compilerEs pod that compiles Fantom types to ES
  3. We have a new nodeJs pod that will be the tool for working with Fantom code in the NodeJS environment
  4. The testDomkit pod can run the new ES code in the browser
  5. Many of the core testSys tests are passing (and in some case more tests are passing than with the old JS!); though this is still a work in progress to verify the test suite.

The plan for now is to continue design review and implementation in the forked repo. We would like to get community feedback specifically on the design and implementation decisions within the next few months. Currently, we are able to run both the old JS pipeline and the new ES pipeline side-by-side. We intend to keep it this way in the interim with the goal of transitioning to the new implementation by next summer (2024).

Thanks for your input and look forward to hearing from you!

Gary Thu 17 Aug 2023

Sounds good! :)

Login or Signup to reply.