Over a million developers have joined DZone.
Platinum Partner

Google’s Traceur: compile ECMAScript.next to JavaScript on the fly

· Web Dev Zone

The Web Dev Zone is brought to you in partnership with Mendix. Download this Forrester Report to gain a better understanding of the low-code platform market and how to make a strategic platform selection you won’t regret.

Google’s Traceur allows you to use ECMAScript.next features right now: Write ECMAScript.next code and use a special script type. Then the first script you load is Traceur which ensures that all your new code is compiled to JavaScript on the fly.

Getting started

<html>
  <head>
    <script src="http://traceur-compiler.googlecode.com/.../traceur.js"
        type="text/javascript"></script> 
    <script src="http://traceur-compiler.googlecode.com/.../bootstrap.js"
        type="text/javascript"></script>
    <script type="text/traceur">
        // Your ECMAScript.next code goes here
    </script>
  </head>
  ...
</html>


Supported features

Highlights (details: see language features):

  • Inheritance: classes, traits
  • Modules
  • Iterators, for-each loop, generators, deferred functions
  • Block-scoped let bindings
  • Destructuring assignment
  • Parameter handling: default values, rest parameters, spread operator


Caveats

Brendan Eich mentioned Traceur in his JSConf.US presentation. And he was unhappy about a few details. You should also read Alex Russell’s response to his complaints.

  • The project raises concerns about openwashing: Is Google’s actual agenda behind this open source project to control where ECMAScript.next is going? Probably not, but the following points set a tone that is slightly off.
  • Traceur has been created in secret, without involving TC39, and then presented for maximum “wow” effect at JSConf (Eich calls this “delayed open source” which can be a means of control). In contrast, Mozilla’s Narcissus has always been developed in the open, to foster discussion with the community.
  • Some features are different from current ES.next proposals. This risks forking the community.
  • The JSConf Traceur slides are Chrome-only, neither (mobile) Safari nor Firefox works. Alex Russell’s explanation: “As for the slides, that looks to be a bug in Traceur support for FF which we’re still sorting through.” But the problem exists on Safari, too, which does not bode well for cross-browser compatibility.

Let’s hope these are just initial issues, because Traceur is a cool project. This kind of on-the-fly compiling is the way to ensure a smooth transition from ECMAScript 5 to ECMAScript.next.

Related reading

The Web Dev Zone is brought to you in partnership with Mendix. Better understand the aPaaS landscape and how the right platform can accelerate your software delivery cadence and capacity with the Gartner 2015 Magic Quadrant for Enterprise Application Platform as a Service.

Topics:

Published at DZone with permission of Axel Rauschmayer , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}