Modules Loader.load function

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Modules Loader.load function

Guy Bedford
I see there are now two load functions for the ES6 module loader - 'Loader.import' and 'Loader.load'. Loader.import seems to apply the full normalization process, while Loader.load takes a url directly. This sounds like a good feature to me.

From the code comments in the reference loader at https://github.com/jorendorff/js-loaders/blob/master/loaders.js#L142 it seems that any 'import' statements in code loaded with 'Loader.load' will still be respected.

I was wondering if 'export' statements would similarly cause a module to be returned by the 'Loader.load', and if so, why is the 'type' metadata in the translate and link hooks necessary? Surely the lack of a 'normalized' property in the metadata would implicitly indicate this anyway?

Thanks,

Guy

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Modules Loader.load function

Sam Tobin-Hochstadt
On Fri, Jun 21, 2013 at 6:00 PM, Guy Bedford <[hidden email]> wrote:
> I see there are now two load functions for the ES6 module loader -
> 'Loader.import' and 'Loader.load'. Loader.import seems to apply the full
> normalization process, while Loader.load takes a url directly. This sounds
> like a good feature to me.

These are different in other, more important ways as well.  In
particular, `Loader.import` references a module name, (potentially)
fetches it, defines the relevant module, and returns the module
instance object to the callback, whereas `Loader.load` is basically
the (async) composition of XHR and `Loader.evalAsync`.

> From the code comments in the reference loader at
> https://github.com/jorendorff/js-loaders/blob/master/loaders.js#L142 it
> seems that any 'import' statements in code loaded with 'Loader.load' will
> still be respected.

Yes, `.load()` is like `.evalAsync()`.

> I was wondering if 'export' statements would similarly cause a module to be
> returned by the 'Loader.load', and if so, why is the 'type' metadata in the
> translate and link hooks necessary? Surely the lack of a 'normalized'
> property in the metadata would implicitly indicate this anyway?

Using `export` at the top level of code passed to `Loader.load` is a
syntax error, the same way it would be a syntax error to use `export`
at the top level of any other script.

Sam
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss