ES6 doesn't need opt-in

Andreas Rossberg rossberg at google.com
Tue Jan 3 01:29:10 PST 2012


On 3 January 2012 07:19, Brendan Eich <brendan at mozilla.com> wrote:
> [Dave has been traveling, hope it's ok for me to jump in. /be]
>
> On Jan 2, 2012, at 6:07 AM, Andreas Rossberg wrote:
>
>> In other words, I think the main points of your proposal can
>> essentially be rephrased to:
>>
>> 1) Rename "use version 6" to "use module".
>> 2) Allow module declarations in classic mode.
>
> [Replying to (1) and (2) here:]
>
> Not just module declarations -- all new syntax that is not backwards-incompatible: destructuring, rest/spread, for/of ,generators, comprehensions, generator expresions, quasiliterals, more.

Yes, but that is a totally independent choice. We could do that
regardless of Dave's proposal. And I agree, there probably is no good
reason not to. Maybe we can even get "let" in?

>> 3) Make every module body start with an implicit "use module".
>
> That's not right: use module; in a pragma turns the enclosing block or body into a module {...}, in a macro-like way. Then if the module {...} is illegal in the given context (i.e., not nested immediately in another module's body), you get the same error you'd get trying to write, e.g.,
>
>  if (cond) { module { /* stuff */ } }

Hm, I don't follow. How is this related to point (3)? The body of a
module always is a context where module declarations are allowed.

Isn't it rather a reply to my item (1) above? If so, my assumption
always has been that "use version 6" would only be allowed on the
top-level, and not fine-grained in individual functions like "use
strict", since that would run havoc with lexical scoping.

>> 4) Keep the semantics of the top-level scope unaltered, even in
>> presence of a top-level "use module".
>
> No, see above: that turns the verbatim top level into the ... part of module {...}.

OK, I see, but then we effectively have opted out of the global
object, at least as a carrier for the verbatim top-level declarations
of the (current) script, haven't we? So I'm not sure how that even
differs substantially from what we have been discussing so far
regarding the global object. We could still decide to (or not to)
remove the global object from the scope chain entirely in that case.

>> I'm fine with (1) to (3), but (4) seems to be a separate design choice.
>
> With what I wrote above in mind, what do you think now?

Since I'm no longer clear what change (relative to our, admittedly
vague, recent discussion) Dave is actually proposing wrt the
top-level, I don't know. Maybe there is no (4) at all, which I'd be
fine with, of course. :)

/Andreas


More information about the es-discuss mailing list