ES Modules: suggestions for improvement

David Bruant bruant.d at
Wed Jun 27 02:21:08 PDT 2012

Le 27/06/2012 11:09, Brendan Eich a écrit :
> David Bruant wrote:
>> Le 27/06/2012 10:31, Brendan Eich a écrit :
>>> David Bruant wrote:
>>>> Le 26/06/2012 16:44, David Bruant a écrit :
>>>>> Also relevant to this thread, post on the same topic by Isaacs 
>>>>> (node.js lead) :
>>>> "Furthermore, |let| already gives us destructuring assignment. If a 
>>>> module exports a bunch of items, and we want several of them, then 
>>>> do |var {x,y,z} = import 'foo'| or some such."
>>>> => Excellent idea. That combined with the single export idea 
>>>> reduces the amount of new syntax to introduce.
>>> Declarations can nest under control flow constructs, but import or 
>>> module dependencies must be prefetched. They're static.
>>>   if (some_rare_condition()) { let x = import "m"; ... }
>>> either always prefetches "m", which does not say what is meant;
>> True.
>> It could be considered to allow 'let x = import "m";' only at the top 
>> level.
>> But if it's the case, having a specific lexical form makes clearer 
>> that it's a module import and not a regular assignment.
> The other point people seem to miss about import as a special binding 
> form is not just that it can be restricted grammatically to be 
> control-insensitive by construction: it's that static export vs. 
> import checking can be done to catch typos.
> This is a significant point, but it's either missed or assumed 
> insignificant. I think we should have a stand-up argument about it. 
> Static module systems are static, in dependency prefetching, in 
> binding, and in export vs. import checking.
Import checking is definitely a feature that's worth it, but Isaacs idea 
to being able to import jQuery (or any library of course) as is by 
having the module global scope into the "export object" without 
polluting the actual global object seems to is definitely a win.
Being able to import existing libraries as modules without changing a 
bit of the library, without even having to read it or worry about global 
leaks is a strong win in my opinion. It's worth not having the typo 
check for this particular case.
Import checking can still be added afterward.


More information about the es-discuss mailing list