Import Expressions

Calvin Metcalf calvin.metcalf at
Fri Jan 31 13:25:37 PST 2014

if import statements could function as AssignmentExpression, they would be
a lot more useful,  something like

var foo = import 'ModuleSpecifier';

It could still be statically linked regardless of whether the code was run,
but instead of creating a binding, the modules loaded in this way could be
stored in a Map, calls to import would resolve to the entry for the module.
 If the module has a default export it would be returned, otherwise it
would return the module object.

This would not effect the loading semantics as the modules would still be
loaded once at the top of the scope, and the always loading even if the
code never runs has not proven to be an issue in AMD modules (when they are
used as define(function(require, exports, module){}).

You guys have been doing heroic work and I (and others I'd assume) are very
grateful and something for imports along these lines would help with
patterns that a lot of experience in node and AMD has shown to be common,
much like the default exports helped make exports feel a lot saner when
coming in from CommonJS/AMD.

Thanks for all your work guys.

-Calvin W. Metcalf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list