Nested modules clarification

David Herman dherman at mozilla.com
Wed Jul 18 21:35:36 PDT 2012


On Jul 18, 2012, at 9:15 AM, ๏̯͡๏ Jasvir Nagra wrote:

> On Wed, Jul 18, 2012 at 4:25 AM, Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:
> 
> Lexical bindings as well as module definitions:
> 
> module outer {
>   let x = 1;
>   export module inner {
>     export y = x + 2;
>   }
> }
> 
> That's a little unexpected.  Would the same hold if the above code was refactored so the inner module was a separate file?
> 
> module outer {
>   let x = 1;
>   export module inner = "http://m/inner.js";
> }

No, an external file only has access to the global scope, so x would not be visible to the module in the external file.

> If not, should a module inliner be doing variable renaming in order to maintain semantics?

It shouldn't be much of an issue if they're only being inlined at top level. E.g., transforming module files m1.js, m2.js, m3.js into a single file:

    module m1 { /* contents of m1.js */ }
    module m2 { /* contents of m2.js */ }
    module m3 { /* contents of m3.js */ }

Should be exactly equivalent except for the names m1, m2, and m3. So you'd only need to synthesize fresh variable names for the generated modules.

But maybe I'm missing what kind of inliner you're thinking of?

Dave

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


More information about the es-discuss mailing list