google / traceur-compiler

Traceur is a JavaScript.next-to-JavaScript-of-today compiler
Apache License 2.0
8.17k stars 581 forks source link

Simplify modules=instantiate|register mess #1408

Open vojtajina opened 10 years ago

vojtajina commented 10 years ago

My suggestion:

1/ rename "instantiate" to something like "es6loader" 2/ remove "register" - what is the purpose of it? (AFAIK, there is no Loader.register API in the spec) 3/ make it possible to use modules="es6loader" output with es6-module-loader, without systemjs - what needs to be done?

What do you think? Am I missing something?

vojtajina commented 10 years ago

@guybedford

johnjbarton commented 10 years ago

What mess?

Traceur compiles itself using 'register'. You can load these modules with only ModuleStore, that's what we do do bootstrap.

If you don't want a system registry, use 'inline'.

guybedford commented 10 years ago

I know it is not ideal but backwards compatibility around this may be important now - we've been communicating for 9 months now the modules=instantiate option, so I'd be hesitant to change this.

You can use System.register on its own by simply adding it at the end of es6-module-loader.js.

arv commented 10 years ago

What mess?

I agree that this is a bit messy.

Here are the modes I would prefer

  1. AMD/CJS
  2. Bundle - No runtime module support. All bindings are shared across modules so import and export use the same binding.
  3. System - all at runtime, no precompiled files.
domenic commented 10 years ago

It's worth looking at es6-module-transpiler for alternative approaches. I think they do it pretty well. Out of the box they only have "bundle." There are plugins for AMD and for CJS. I don't think they have anything System-related (but I never understood what parts of System are standard and which are @guybedford's extensions).

johnjbarton commented 10 years ago

Well I think we should switch to use 'instantiate' for Traceur and remove 'register'. As far as I know, es6-module-loader uses 'instantiate' for bundles. I tried switch one time as part of trying to replace TraceurLoader with es6-module-loader, but I could not solve all of the problems. May just the switch would be easier.

I would be against using 'inline' for Traceur, it's too hard to read.

vojtajina commented 10 years ago

@arv what does bundle mean? Is it all files into one?

Right now, I have to use es6-module-loader and systemjs (with "register" extension) to load Traceur's output. It should be possible to load code generated by Traceur using plain es6-module-loader.

johnjbarton commented 10 years ago

To me a good solution is the one we use for Traceur. Start with runtime file like bin/traceurRuntime.js and a compiled file generated from a command line compile like ./traceur <options> --module <rootModule>. Including both files in <script> tags and you can run a web page. Or add more <rootModule> based files. Or concatenate them. Or try out the code without compilation by putting a <script> tag withbin/traceur.jsin the web page and usingSystem.import().then(...). Or usees6-module-loaderthen useSystem.import().then(...). Ifbin/traceurRuntime.js` is really too large, build a smaller one with a custom script.

If you want to go to the next level and mix cjs/requirejs into the app use type='module' tags, and allow both static and dynamic loads then you want @guybedford's systemjs, it deals with all that.