Modules: Curly Free

Kevin Smith zenparsing at gmail.com
Mon Apr 22 04:26:10 PDT 2013


>
>
>
> I understand, I'm just not convinced.  I'm still on the fence.
>
>
In any case, the cure must leave us better off than the disease, so let's
focus on the other side of the equation and see what kind of cure we can
come up with.

Let's say that each module has some "default" export.  Let's follow from
the Node/AMD example and allow the default "default" to be the module
export map.  As with Node/AMD, this default can be overridden with some
explicit declaration.

On the consumer side, we could do something like this:

    // Imports the "default" export, either the module instance object
    // or some explicitly specified binding
    import "abc" as abc;

That looks nice, but it leaves us without a way to get to the module
instance object in cases where the default has been overridden.  We could
use some lookahead to fix that:

    // Imports the module instance object, regardless of explicit default
    import module "abc" as abc;

Or we could just leave off the import keyword:

    // Another option:
    module "abc" as abc;

This also looks nice:

    // Another option:
    module abc from "abc";

Now to the provider side of things.  Dave's idea of using the "default"
keyword sounds good to me.  We could go fully anonymous, as Dave suggests.
 If so, then I think we need a "=" to signal to the human reader that an
expression context follows:

    export default = function() { ... }; // (A)

Or we could flag a regular old export declaration as having the special
"default" property, like so:

    export default function Z() { ... } // (B)

An upside to (B) is that we can use the exported identifier in an import
list:

    // With option (B)
    import Z, a, b, c from "z-stuff.js";

    // With option (A)
    import "z-stuff.js" as Z;
    import a, b, c from "z-stuff.js";

I think it can be done elegantly.  I'm not sure how necessary it is, but I
don't think adding a "default" export needs to inflict too much violence on
the model or the grammar.

>From the fence...

{ Kevin }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130422/3fcc15c8/attachment.html>


More information about the es-discuss mailing list