ECMAScript:Harmony / ES6 to JavaScript compiler

后端 未结 8 877
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 13:37

After reading Peter\'s article on JavaScript I noticed

Brendan Eich stated that one the goals for Harmony is to be a better target for to-JavaScript c

相关标签:
8条回答
  • 2020-12-12 14:15

    Continuum has implemented most of the relevant features and should run in es3 browsers (like older IEs).

    0 讨论(0)
  • 2020-12-12 14:20

    (shameless but relevant plug below)

    Caja is reworking its ES5 support via ES5/3 and will do the same for ES harmony. So our structure would be implemented as a Harmony to ES3 layer which can be skipped for real harmony implementations, and then a separable loader that preserves the security properties that concern caja.

    Like Traceur, members of the Caja team are part of TC39 (the committee defining ES Harmony).

    I don't know about Coffeescript's plans, but it was mentioned during discussions of Harmony modules. Module loaders will likely have the ability to intercept loaded source code (via eval hooks) and rewrite it before module initialization, so if a module is written in CoffeeScript, a runtime CoffeeScript rewriter could be invoked at initialization time. This would allow apps to be composed of modules written in multiple languages that compile down to Harmony at load time.

    One thing to note is that not everything in Harmony can be implemented easily via translation. For example, implementing weak maps correctly would require implementing your own garbage collector in JavaScript and even if you did that you would probably just reintroduce the host object/native object cycle problem.

    0 讨论(0)
  • 2020-12-12 14:21

    Check out TypeScript, Microsoft's new language based on ES6.

    0 讨论(0)
  • 2020-12-12 14:23

    Google Closure Compiler (Github) is a great tool for ES6 compilation. It's a simple Java jar that is used from the command line. There are other options such as API services and GUIs, but I find that it was best to set up an automatic build system hooking into the Java JAR. It can transpile your ES6 code into ES5 compatible code. I started using it for compressing and obfuscating code, but it can also do error checking and the ES6 transpilation as I mentioned.

    Note that the ES6 features are marked as experimental. But I'm planning on using them in production soon, since my tests were rock solid.

    0 讨论(0)
  • 2020-12-12 14:28

    Mascara is probably what you're looking for.

    0 讨论(0)
  • 2020-12-12 14:31

    I'm not sure in what instance compilation back to ES3 would valuable as opposed to ES5, seeing that implementation changes are limited to array and object helper functions, and ES5 support is so prevalent.

    So for completeness, another ES6 to ES5 compiler is the esnext project by Square. It is a collection of a number of modules designed to polyfill various ES6 features provided in one package. Here is the list modules included: https://github.com/square/esnext#available

    0 讨论(0)
提交回复
热议问题