On 26 January 2012 17:47, Allen Wirfs-Brock <[email protected]> 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 *".
> (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.
I still like the idea of cross-script shadowing (aka nested scopes),
but one concern was that it is not clear what names would be in scope
for, say, a piece of JS code in a random HTML attribute somewhere on
the page. That applies to imports no less than let. I still don't
really buy that argument (because it's no clearer if scopes are not
nested), but IIRC it was one reason the idea was shot down.
/Andreas
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss