let and strict mode

Brendan Eich brendan at mozilla.com
Sat Nov 17 18:06:04 PST 2012


Dave Herman proposed as part of 1JS that module imply strict mode, so 
let is reserved in module. So that helps.

For let outside of modules, we could contextually parse let at start of 
statement if followed by an identifier or a { that starts an object 
pattern. We could even allow LineTerminator after let, and perhaps 
should try to get away with that.

But if we allow LineTerminator and risk some backward incompat, can we 
up the ante by allowing [ after let?

Who knows, but we have some choices:

1. 'let' only in strict code including modules per 1JS as originally 
proposed.

2. 'let' followed by identifier or { but not LineTerminator.

3. 'let' followed by identifier or { with LineTerminator and other space 
allowed in between.

4. 'let' followed by identifier, {,  or [ and LineTerminator in between 
is ok.

5. We could also allow 'let' per (4) in functions not in modules that do 
not "use strict" but do use new ES6 syntax in their heads, e.g. 
destructuring parameters, default parameters, rest parameters. Those 
head features could arguably opt into 'let' syntax but not strict mode.

Comments?

/be

Kevin Smith wrote:
>
>         var let = function() {};
>         let();
>
>
> If let is a contextual keyword (in non-strict mode of course), then we 
> can look ahead to the token after `let` to validate it.  An open paren 
> cannot follow a let *keyword*, so therefore it must be an identifier.
>
>        var let = { it: "be" };
>     let.it <http://let.it> // be
>
>
> Same logic applies.  A dot cannot follow a let keyword so we parse it 
> as an identifier.
>
> On the other hand, an open square bracket *can* follow a let keyword 
> (by array destructuring), so we have a potential ambiguity there.
>
> - Kevin


More information about the es-discuss mailing list