The global object should not be the "global scope instance object"

Allen Wirfs-Brock allen at wirfs-brock.com
Thu Jan 26 14:31:35 PST 2012


On Jan 26, 2012, at 11:26 AM, Andreas Rossberg wrote:

> On 26 January 2012 17:47, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>> On Jan 26, 2012, at 3:01 AM, Andreas Rossberg wrote:
>>> Overlapping imports? That's the first time I hear about that. That
>>> might be rather difficult, given that modules are recursive.
>> 
>> It's just something I threw in that the module champions need to weigh in on.  It seems desirable to allow things like:
>> 
>> <script>
>> import {create} from "@names";
>> const foo = create();
>> </script>
>> <script>
>> import {create} from "@names";
>> const bar = create();
>> </script>
> 
> I agree it's useful, but so are other forms of shadowing.
> 
> Module scoping is difficult, especially if you want a semantics that
> can be decided efficiently. Moreover, shadowing and recursion (and
> every ES6 scope is recursive) don't go together well. And things get
> even more interesting with "import *".

Can you give an example of what you mean by "recursive" in this context? Do you mean that a scope can contain references to bindings defined by the scope?

> 
>> (and, of course, the scripts would most likely be independent files).
>> I don't see why circularities involving the imported module would create any problems in this situation.  It probably helps that we are talking about top level scripts that aren't themselves modules.
> 
> You might get away with duplicate imports in separate scripts, like in
> your example. But AFAICS, that essentially amounts to reintroducing
> the multiple-scripts-as-nested-scopes idea through the backdoor. Just
> consider that in the presence of import shadowing, you could rewrite
> 
>  let x = e
> 
> to
> 
>  module __fresh_name__ { export let x = e }
>  import {x} from __fresh_name__
> 
> and thereby have the same effect as if shadowing was allowed for let.

Huh?

<script>
module _fn_ {export let x = e}
import {x} from _fn_
</script>
<script>
import {x} from _fn_
</script>

seems quite different from

<script>
let x=e;
</script>
<script>
let x=e;
</script>

with shadowing. The module case only has a single x that is initialized only one. The shadowing case has two x and each is initialize separately.  This is easily observable between scripts blocks by calling/passing around closures that capture one of the x or the other.



More information about the es-discuss mailing list