ES modules: syntax import vs preprocessing cs plugins

Claus Reinke claus.reinke at
Fri Jul 6 06:17:36 PDT 2012

> Ok, this will work fine using the multiple script tags approach you 
> showed.

Actually, I no longer think that third approach will work: there
is no reason why the load callback in the first script element
should run before the code in the second script element, so
'main' will not be available there.

>> Okay, that solves part of the problem for client-side apps. We
>> can use extended loaders without having to switch every import
>> to callback style.

That means I'm back to square one: no way to use extended loaders
without rewriting every module construct to callbacks.

>> .. there are decisions which tc39 needs to leave to the bodies
>> standardizing the ES host environments. Nevertheless, it should
>> be possible to write cross-platform ES code without reference to
>> the host environment.
> In so far as the ES spec makes no reference to files, script tags, or
> REPLs, this would be a big step in tc39 taking over the responsibility
> of designing other people's systems. For browsers, tc39 has most of
> the vendors in the room, but that's not the case for other kinds of JS
> embeddings.
> If you have a suggestion for how this could work, I'm all ears, but so
> far, this sounds unlikely.

It should not be necessary to reference external elements any
more than in the rest of the modules spec. As a fallback approach
(if we don't find anything else), we could take a leaf from the AMD
loader plugins (things like "text!resource"):

    import {b} from 'b' using 'myLoader.js';
    .. other imports ..
    .. lots of code that uses imports ..

Since modules are resolved before code is run, we cannot easily
get myLoader from the current scope (in HTML, it could come from
a previous script element, but how would that work in node?). So
the idea is to fetch loaders themselves as modules:

If 'myLoader.js' contains a module with an export interface that
corresponds to a module loader, then the import-from-using
line could use that loader to do the import.


More information about the es-discuss mailing list