Closed Bug 1032150 Opened 10 years ago Closed 8 years ago

Using "let" and "yield" as (Binding)Identifiers should only be a SyntaxError in strict code

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: Swatinem, Unassigned)

References

Details

While "yield" is defined as a keyword, it is explicitly allowed as identifier in "some contexts" (see http://people.mozilla.org/~jorendorff/es6-draft.html#sec-keywords)

http://people.mozilla.org/~jorendorff/es6-draft.html#sec-identifiers-static-semantics-early-errors also states that "let" is only a reserved keyword in strict code.

Currently both fail when using them as identifiers:
```
js> let = 10
typein:1:4 SyntaxError: missing variable name:
typein:1:4 let = 10
typein:1:4 ....^
js> yield = 10
typein:2:0 SyntaxError: yield not in function:
typein:2:0 yield = 10
typein:2:0 ^
```

In nodejs (v8), using yield works fine, but they throw a SyntaxError for "let" as well
```
> yield = 10
10
> let = 10
SyntaxError: Illegal let declaration outside extended mode
```
Same goes for "eval" and "arguments" when being used as BindingIdentifiers.
Summary: Using "let" and "yield" as identifiers should only be a SyntaxError in strict code → Using "let", "yield", "eval" and "arguments" as (Binding)Identifiers should only be a SyntaxError in strict code
I’m fixing "eval" and "arguments" in destructuring in bug 933276.
Summary: Using "let", "yield", "eval" and "arguments" as (Binding)Identifiers should only be a SyntaxError in strict code → Using "let" and "yield" as (Binding)Identifiers should only be a SyntaxError in strict code
Keywords: dev-doc-needed
Whiteboard: [DocArea=JS]
Blocks: es6:let
No longer blocks: es6
Threading YieldHandling through the entire parser in bug 1155472 should have, I believe, fixed the issue of |yield| as identifier.  (1.7-versioned code does still have legacy generators, but non-standard code can do non-standard things -- as long as non-versioned normal code does the right thing, I think we handle |yield| correctly per this bug's complaint.)

And re |let|, I think bug 1233249 fixed the bug that you could declare let/const variables named |let|.  That's the last remaining let/const identifier bug I'm aware of.

So I'm going to mark this fixed.  Let's file any remaining issues in new bugs, with the issue precisely marked.  (Then we won't be in a situation again of having an open bug, that we can't easily identify as still a problem or no longer a problem.)
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Keywords: dev-doc-needed
Whiteboard: [DocArea=JS]
You need to log in before you can comment on or make changes to this bug.