Skip to content

Commit

Permalink
Merge pull request #1023 from anba/redeclaration
Browse files Browse the repository at this point in the history
Lexical redeclarations in block- and switch-statements

Background feedback from @anba:

In https://tc39.github.io/ecma262/#sec-switch-statement-static-semantics-lexicallydeclarednames, all lexically declared names from the different case clauses are combined.
For each case clause, the LexicallyDeclaredNames definition from https://tc39.github.io/ecma262/#sec-block-static-semantics-lexicallydeclarednames applies, which has:

```
StatementListItem : Declaration
  1. Return the BoundNames of Declaration.
```

And in https://tc39.github.io/ecma262/#prod-Declaration we've got:

```
Declaration[Yield, Await] : HoistableDeclaration[?Yield, ?Await, ~Default]
```

And in https://tc39.github.io/ecma262/#prod-HoistableDeclaration:

```
HoistableDeclaration[Yield, Await, Default] : FunctionDeclaration[?Yield, ?Await, ?Default]
```

And the BoundNames of a FunctionDeclaration is its BindingIdentifier https://tc39.github.io/ecma262/#sec-function-definitions-static-semantics-boundnames.

And there's also B3.3.5 (https://tc39.github.io/ecma262/#sec-switch-duplicates-allowed-static-semantics) which allows duplicate FunctionDeclarations in sloppy mode in switch-statements.
  • Loading branch information
leobalter committed May 5, 2017
2 parents fbf992b + 49221fc commit 9481020
Show file tree
Hide file tree
Showing 240 changed files with 3,574 additions and 159 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-
name: AsyncFunctionDeclaration in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains
any duplicate entries.
negative:
phase: early
type: SyntaxError
flags: [async-functions]
---*/

{ async function f() {} /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/async-generator-declaration-attempt-to-
name: AsyncGeneratorDeclaration in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains
any duplicate entries.
negative:
phase: early
type: SyntaxError
flags: [async-iteration]
---*/

{ async function* f() {} /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/class-declaration-attempt-to-
name: ClassDeclaration in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains
any duplicate entries.
negative:
phase: early
type: SyntaxError
---*/

{ class f {} /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/const-declaration-attempt-to-
name: LexicalDeclaration (const) in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains
any duplicate entries.
negative:
phase: early
type: SyntaxError
---*/

{ const f = 0; /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/function-declaration-attempt-to-
name: FunctionDeclaration in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains
any duplicate entries.
negative:
phase: early
type: SyntaxError
flags: [onlyStrict]
---*/

{ function f() {} /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-
name: GeneratorDeclaration in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains
any duplicate entries.
negative:
phase: early
type: SyntaxError
---*/

{ function* f() {} /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/let-declaration-attempt-to-
name: LexicalDeclaration (let) in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains
any duplicate entries.
negative:
phase: early
type: SyntaxError
---*/

{ let f; /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/var-declaration-attempt-to-
name: VariableDeclaration in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if any element of the LexicallyDeclaredNames of
StatementList also occurs in the VarDeclaredNames of StatementList.
negative:
phase: early
type: SyntaxError
---*/

{ var f; /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-
name: AsyncFunctionDeclaration in SwitchStatement
esid: sec-switch-statement-static-semantics-early-errors
info: |
SwitchStatement : switch ( Expression ) CaseBlock

It is a Syntax Error if the LexicallyDeclaredNames of CaseBlock contains any
duplicate entries.
negative:
phase: early
type: SyntaxError
flags: [async-functions]
---*/

switch (0) { case 1: async function f() {} default: /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/statements/switch/syntax/redeclaration/async-generator-declaration-attempt-to-
name: AsyncGeneratorDeclaration in SwitchStatement
esid: sec-switch-statement-static-semantics-early-errors
info: |
SwitchStatement : switch ( Expression ) CaseBlock

It is a Syntax Error if the LexicallyDeclaredNames of CaseBlock contains any
duplicate entries.
negative:
phase: early
type: SyntaxError
flags: [async-iteration]
---*/

switch (0) { case 1: async function* f() {} default: /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-
name: ClassDeclaration in SwitchStatement
esid: sec-switch-statement-static-semantics-early-errors
info: |
SwitchStatement : switch ( Expression ) CaseBlock

It is a Syntax Error if the LexicallyDeclaredNames of CaseBlock contains any
duplicate entries.
negative:
phase: early
type: SyntaxError
---*/

switch (0) { case 1: class f {} default: /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/statements/switch/syntax/redeclaration/const-declaration-attempt-to-
name: LexicalDeclaration (const) in SwitchStatement
esid: sec-switch-statement-static-semantics-early-errors
info: |
SwitchStatement : switch ( Expression ) CaseBlock

It is a Syntax Error if the LexicallyDeclaredNames of CaseBlock contains any
duplicate entries.
negative:
phase: early
type: SyntaxError
---*/

switch (0) { case 1: const f = 0; default: /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-
name: FunctionDeclaration in SwitchStatement
esid: sec-switch-statement-static-semantics-early-errors
info: |
SwitchStatement : switch ( Expression ) CaseBlock

It is a Syntax Error if the LexicallyDeclaredNames of CaseBlock contains any
duplicate entries.
negative:
phase: early
type: SyntaxError
flags: [onlyStrict]
---*/

switch (0) { case 1: function f() {} default: /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-
name: GeneratorDeclaration in SwitchStatement
esid: sec-switch-statement-static-semantics-early-errors
info: |
SwitchStatement : switch ( Expression ) CaseBlock

It is a Syntax Error if the LexicallyDeclaredNames of CaseBlock contains any
duplicate entries.
negative:
phase: early
type: SyntaxError
---*/

switch (0) { case 1: function* f() {} default: /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/statements/switch/syntax/redeclaration/let-declaration-attempt-to-
name: LexicalDeclaration (let) in SwitchStatement
esid: sec-switch-statement-static-semantics-early-errors
info: |
SwitchStatement : switch ( Expression ) CaseBlock

It is a Syntax Error if the LexicallyDeclaredNames of CaseBlock contains any
duplicate entries.
negative:
phase: early
type: SyntaxError
---*/

switch (0) { case 1: let f; default: /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/statements/switch/syntax/redeclaration/var-declaration-attempt-to-
name: VariableDeclaration in SwitchStatement
esid: sec-switch-statement-static-semantics-early-errors
info: |
SwitchStatement : switch ( Expression ) CaseBlock

It is a Syntax Error if any element of the LexicallyDeclaredNames of
CaseBlock also occurs in the VarDeclaredNames of CaseBlock.
negative:
phase: early
type: SyntaxError
---*/

switch (0) { case 1: var f; default: /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-
name: AsyncFunctionDeclaration in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if any element of the LexicallyDeclaredNames of
StatementList also occurs in the VarDeclaredNames of StatementList.
negative:
phase: early
type: SyntaxError
flags: [async-functions]
---*/

{ async function f() {} /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/async-generator-declaration-attempt-to-
name: AsyncGeneratorDeclaration in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if any element of the LexicallyDeclaredNames of
StatementList also occurs in the VarDeclaredNames of StatementList.
negative:
phase: early
type: SyntaxError
flags: [async-iteration]
---*/

{ async function* f() {} /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/class-declaration-attempt-to-
name: ClassDeclaration in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if any element of the LexicallyDeclaredNames of
StatementList also occurs in the VarDeclaredNames of StatementList.
negative:
phase: early
type: SyntaxError
---*/

{ class f {} /*{ body }*/ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
path: language/block-scope/syntax/redeclaration/const-declaration-attempt-to-
name: LexicalDeclaration (const) in BlockStatement
esid: sec-block-static-semantics-early-errors
info: |
Block : { StatementList }

It is a Syntax Error if any element of the LexicallyDeclaredNames of
StatementList also occurs in the VarDeclaredNames of StatementList.
negative:
phase: early
type: SyntaxError
---*/

{ const f = 0; /*{ body }*/ }

0 comments on commit 9481020

Please sign in to comment.