Modules, Concatenation, and Better Solutions

Sam Tobin-Hochstadt samth at ccs.neu.edu
Wed Oct 17 09:43:46 PDT 2012


On Wed, Oct 17, 2012 at 12:40 PM, Allen Wirfs-Brock
<allen at wirfs-brock.com> wrote:
>
> On Oct 17, 2012, at 9:09 AM, Sam Tobin-Hochstadt wrote:
>
>> On Wed, Oct 17, 2012 at 9:51 AM, Kevin Smith <khs4473 at gmail.com> wrote:
>>>
>>>> Do we log "you need me" only when f is called for the first time?
>>>
>>>
>>> Sorry - that makes no sense.  What I meant was:
>>>
>>>    module A {
>>>      console.log("you need me");
>>>      export var x = "x";
>>>    }
>>>
>>>    export function f() {
>>>      console.log(A.x);
>>>    }
>>>
>>> Do we log "you need me" only when f is called for the first time?
>>
>> I think that would be far to hard to understand.  Instead, we should
>> treat a module with a reference like `A.x` to an unimported module as
>> if it implicitly had an import of `A`, so "you need me" would be
>> logged as soon as the surrounding module was imported, even if `f` is
>> never called.
>> --
>
>
> Is the reference to A required to get the implicit import and hence implicit initialization?  For example in:
>
> module Outer {
>    /* no export */ module A {
>      console.log("you need me");
>      export var x = "x";
>    }
>
>    export function f() {
>      console.log("no reference to A");
>    }
> }
>
> I would expect inner modules to always be initialized when their outer module is initialized

That would make the semantics of wrapping things in a module, and then
importing that module, substantially different than just having a
top-level module.  I think regularity suggests that "you need me" not
be logged here.
-- 
sam th
samth at ccs.neu.edu


More information about the es-discuss mailing list