Modules, Concatenation, and Better Solutions

Russell Leggett russell.leggett at gmail.com
Wed Oct 17 14:04:50 PDT 2012


On Wed, Oct 17, 2012 at 1:59 PM, Kevin Smith <khs4473 at gmail.com> wrote:

>
> So any reference to A (not necessarily dotted)  in the outer module
>> triggers hoisted initialization of A? And if  no such reference exists
>> module A is essentially deal code?
>>
>
> So side-effects would be allowed by the language, but would be incredibly
> confounding.  Hmmm....
>

I'm not sure if I like how this is turning out. I think modules should
either not allow side effects, or should be evaluated immediately like an
IIFE. While I appreciate lazy evaluation when it is really utilized like
Haskell, I think it would be very surprising here. If we need to make it
easier for concatenation, maybe what we really want is an easy way to
effectively prime the module loader with a sort of cache so that it only
"loads" the module when needed, in the same way it would work as multiple
http requests, but it never needs to go to the server.

    // a.js
    import b from "b.js";
    console.log("a");
    export let a = "a";

    // b.js
    console.log("b");
    export let b = "b";

    // main.js
    import a from "a.js";
    console.log("main");

becomes

    //lib.js
    module "a.js" {
        import b from "b.js";
        console.log("a");
        export let a = "a";
    }
    module "b.js" {
        console.log("b");
        export let b = "b";
    }

    //main.js
    import a from "a.js";
    console.log("main");

The idea here, is to allow a new bit of syntax where the module identifier
is a string literal. If that is the case, it assumes the module is loaded
in place of a file, where the url for the file is the value of the string
literal. Just to be clear, though, it doesn't actually execute the module
at all - it just caches it in the loader.

Of course, the content in main.js could still just go in lib.js, but I
wanted to point out something important, namely that the import of "a.js"
can be retained *as is* which is another potential problem with module
concat.

- Russ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121017/5cfd1093/attachment.html>


More information about the es-discuss mailing list