Modules, Concatenation, and Better Solutions

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Oct 17 09:54:54 PDT 2012


On Oct 17, 2012, at 9:43 AM, Sam Tobin-Hochstadt wrote:

> 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.

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?

Allen



More information about the es-discuss mailing list