Future ECMAScript version: 'let' should not hoist

RESOLVED INVALID

Status

()

Core
JavaScript Engine
RESOLVED INVALID
7 years ago
6 years ago

People

(Reporter: jimb, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

7 years ago
At present, the following evaluates to 3:

(function () { var x = 3; { x = 4; let x; } return x; })()

However, in bug 553778 comment 14, Brendan says:

> BTW, we resolved without yet spec'ing it even informally to change let in
> Harmony to be like a declaration in C++, or like let* if you will, and not
> hoist (yay!). I convinced everyone this is what people expect and not var-like
> hoisting. So we should have a bug to implement this, and get on with it -- and
> break JS1.[78]* compatibility too.

So: SpiderMonkey should be changed so that the scope of a 'let' declaration is from the point of declaration to the end of the block. This would make the above evaluate to 4.
(Reporter)

Comment 1

7 years ago
It might be a good idea to have a JSOPTION_STRICT and strict mode code warning issued for late lets that would capture new variables, starting now.  And a Reflect-driven tool to search for code that would search for such cases!
(Reporter)

Comment 2

7 years ago
Um, you know what I meant. 'night.
Blocks: 694100
No longer blocks: 694100
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.