State of discussion - module / Import syntax

Shijun He hax.sfo at gmail.com
Sun Oct 7 15:57:36 PDT 2012


On Tue, Sep 25, 2012 at 1:02 AM, Jussi Kalliokoski
<jussi.kalliokoski at gmail.com> wrote:
> I find this interesting as well, because I've been thinking of creating Yet
> Another(TM) module loader, which would be a standalone polyfill for Harmony
> modules.

I just wrote one: https://github.com/hax/my.js/blob/master/src/loader.js


>  * If there's a cross-compilation hook on the loader, does the dependency
> resolving happen before or after the compilation? Former is more efficient,
> but places constraints on the compile-to-JS languages.

I also have the same question. Currently Loader API does not provide
feature to define module dependencies, so only latter is possible as
current draft. In my.js loader implementation, I add extra
"references" property which is accessible in hooks to make former
works.

>  * Is there a way to do async cross-compilation with the hooks? e.g. offload
> parsing and everything to a worker to keep the main thread responsive?

+1. Currently only fetch hook is async, I think translate hook could
also be async so that we can utilize Worker.

On the other hand, fetch hook could also be sync. In fact I suggest follow API:

options.fetch( relURL, baseURL, resolved )

fetch hook returns String (fulfill) or Module instance (skip translate
hook) or throws (reject) or returns a Promise object as async form.

options.translate( data:ModuleData )

ModuleData structure:
{
  data: String // code source
  type: String // mimetype such as text/coffeescript
  uri: String // code uri
  references: [String] // uri references for dependencies
  relativeURL: String // relURL
  baseURL: String
  resolved: Any
  // Note: I dont think relativeURL/baseURL/resolved are useful for
translate hook but just keep them as current draft
}

translate hook returns ModuleData or String (translated source) or
Module instance (skip parent loader translate hooks) or throws
(compilation error) or returns a Promise object as async form.

>  * Is it possible to import things to local scope? For example, is this a
> syntax error, and if not, what happens: `function x () { import y from x }`

I think it should be syntax error.


More information about the es-discuss mailing list