Module syntax

Axel Rauschmayer axel at rauschma.de
Mon Jun 3 12:12:06 PDT 2013


On Jun 3, 2013, at 20:41 , Rick Waldron <waldron.rick at gmail.com> wrote:

> On Mon, Jun 3, 2013 at 2:40 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
>> On Mon, Jun 3, 2013 at 1:29 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
>> Bikeshedding: I generally like the module syntax, but I’d always omit the braces and use `import default` for importing the default export of a module.
>> 
>> From the wiki:
>> 
>> module "foo" {
>>   export default function() { console.log("hello!") }
>> } 
>> ...
>> import default;
>> 
>> What would be the bound name? foo? Am I missing something?
> 
> I’d use:
> import default foo from "foo";
> 
> How is this better then the existing:
> 
>   import foo from "foo";
> 
> For importing a default export?

It’s worse. The point would be to make non-default imports simpler and lose the braces (which make less sense with the new non-literal syntax) in those cases. That is: it makes default imports less convenient in order to make non-default imports more convenient and less grawlixy.

Compare – wiki:
    import $ from "jquery";                    // import the default export of a module
    module crypto from "crypto";               // binding an external module to a variable
    import { encrypt, decrypt } from "crypto"; // binding a module's exports to variables
    import { encrypt as enc } from "crypto";   // binding and renaming one of a module's exports
    export * from "crypto";                    // re-exporting another module's exports
    export { foo, bar } from "crypto";         // re-exporting specified exports from another module
Brace-free:
    import default $ from "jquery";                    // import the default export of a module
    module crypto from "crypto";               // binding an external module to a variable
    import encrypt, decrypt from "crypto"; // binding a module's exports to variables
    import encrypt as enc from "crypto";   // binding and renaming one of a module's exports
    export * from "crypto";                    // re-exporting another module's exports
    export foo, bar from "crypto";         // re-exporting specified exports from another module
Syntactic ambiguities may be a problem, though...

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130603/ec3232be/attachment.html>


More information about the es-discuss mailing list