13.6.3 The for Statement
13.6.4 The for-in and for-of Statements
13.14 The try Statement
12.2.4.2 Array Comprehension
Captured bindings in lexical declarations with destructuring and defaults have different visibility depending on where they appear.
(A) C-style for-loops use this approach:
1. Create new declarative lexical environment
2. Create bindings in the new environment
3. Set the new environment to the currently active lexical environment
4. Perform binding initialization
(B) for-in/of loops, comprehension and catch blocks use this approach:
1. Create new declarative lexical environment
2. Create bindings in the new environment
3. Perform binding initialization
4. Set the new environment to the currently active lexical environment
Use same semantics for both types of statements?
Test case:
---
function f() { let v = 0; for (let {v = () => v} = {};;) return v }
f()(); // () => v
function g() { let v = 0; for (let {v = () => v} of [{}]) return v }
g()(); // 0
function h() { let v = 0; try { throw {} } catch ({v = () => v}) { return v } }
h()(); // 0
function k() { let v = 0; return [for ({v = () => v} of [{}]) v][0] }
k()(); // 0
---
agreed, they should all work, like A.
I'll fix it.
fixed in rev27 editor's draft
fixed in rev27 draft