Javascript Harmony

1,155 views
Skip to first unread message

Maxime Quandalle

unread,
May 9, 2014, 12:42:30 PM5/9/14
to meteo...@googlegroups.com
Hi,

Harmony is the next iteration of the Javascript/Ecmascript specification, introducing features such as generators (yield), block scope (let), shorthand object literals ({a, b}), arrays comprehension, classes and a lot more. Unfortunately we can't use these great features today because of lack of compatibility in some web browsers.

Traceur is a compiler built by Google to compile javascript-next to javascript-of-today. So I've created a small wrapper for Meteor around this compiler. To use it you just have to `mrt add harmony` and then every files ending with `.next.js` will be automatically compiled and bundled in your package or application (with source maps support!).

So now you can use any of these amazing new features: https://github.com/google/traceur-compiler/wiki/LanguageFeatures :-)

Max

James Wilson

unread,
May 9, 2014, 1:22:12 PM5/9/14
to meteo...@googlegroups.com
Awesome!

what is the difference between this and TypeScript?


James Wilson


--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Greenspan

unread,
May 9, 2014, 1:37:15 PM5/9/14
to meteo...@googlegroups.com
Traceur is a compiler that takes ECMAScript 6 (the next version of JavaScript) and outputs ECMAScript 5.

TypeScript is a new programming language from Microsoft that compiles to JavaScript (ECMAScript 3 compatible).

The versions of JavaScript a.k.a. ECMAScript that you might care about:

- ES 3 - This is lowest common denominator, for code that needs to run on IE 6-8
- ES 5 - Adds a lot of new methods, like Array#forEach (see http://kangax.github.io/compat-table/es5/).  Requires IE 9 or later (or a modern browser).
- ES 6 - Mostly not in browsers yet, but the spec is being finalized (see http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts).

I'm pretty excited about ES 6.  It looks like good decisions are being made, the process is converging (with new changes becoming smaller and smaller), and browsers are starting to implement it (like arrow functions in Firefox).

Has anyone taken a critical look at Traceur?  Should everyone start using it (assuming you can drop IE 8)?

-- David

James Wilson

unread,
May 9, 2014, 2:15:32 PM5/9/14
to meteo...@googlegroups.com
Very cool! I have always been a fan of ES6, even using and helping to test and develop Mascara and other tools.

Do you know if there is any plans to make it more like Coffeescript? https://www.npmjs.org/package/typed-coffee-script is my ideal I think.

If we could get ES6 features with optional types and minimal clean syntax like coffeescript I'd be in heaven.


James Wilson

Slava Kim

unread,
May 11, 2014, 1:58:38 AM5/11/14
to meteo...@googlegroups.com, Ja...@jameswilson.name
This looks awesome! I can see Meteor packages authors writing new packages in Coffeescript, ES6 or plain-old javascript! And it all will work fine :)

David Greenspan

unread,
May 11, 2014, 2:07:16 PM5/11/14
to meteo...@googlegroups.com
My friend Pete Hunt (of Facebook/React) writes in:

--

What features do you want? Facebook uses jstransform (our open source thing) which has less features than traceur, but is much faster and smaller footprint. We also have regenerator to cover generators too, but not used that much in prod.

Fwiw all Facebook code is written in es6 and transformed or polyfilled down to ie8. So whether it's jstransform or traceur I recommend it.

(Just be sure to monitor build time)

Mattias Andersson

unread,
May 12, 2014, 5:19:46 PM5/12/14
to meteo...@googlegroups.com
Hello Maxime!

Great job! :)
I quick question, Meteor loads all JS-files while ES6 is module based.
How do you handle that? Or do you just assume that they are ordinary script files?

I'm currently using Traceur with Assist.js for type checking and AngularJS DI 2.0 (only the DI module, not Angular itself) for dependency injection.
This is an awesome setup! Do you think this would be possible with Meteor?

You can watch a short presentation on their ES6 DI implementation here: https://www.youtube.com/watch?v=_OGGsf1ZXMs

Maxime Quandalle

unread,
May 13, 2014, 9:41:11 AM5/13/14
to meteo...@googlegroups.com
I do not handle module compilation specifically for Meteor (yet).

I expect Meteor core developers to fix modules/packages managment, lazy loading, and dependency injector within the package/app API refactor. The backend has already  been prepared for that work during the "Linker" rewrite.
Also I hope that Meteor will allows devs to use the ES 6 import/export API, that the consensual decision that a lot of JavaScript communities have taken.

And BTW I haven't enabled annotations (used by AngularJS DI 2.0) in the traceur compilation config. Should I?

Mattias Andersson

unread,
May 14, 2014, 4:08:47 PM5/14/14
to meteo...@googlegroups.com
Yes you should, it is awesome! :)

Mattias Andersson

unread,
May 14, 2014, 4:20:30 PM5/14/14
to meteo...@googlegroups.com
You should also add types (using Assert.js) if you haven't already.
This gives you modules, classes, typing (with run-time type checks) and dependency injection using annotations. And source maps.
It makes Javascript a quite decent choice for more "enterprise" class development.

Here are my traceur options:
--experimental --source-maps --types=true --type-assertions --type-assertion-module="assert"

assert.js exists.
Reply all
Reply to author
Forward
0 new messages