google / google/closure-compiler

"let" within switch causes variable reference error with outer let

Open
#2,723 5 comments 2 reactions 0 assignees View on GitHub
ES6 P3
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

```js
function foo() {
let c = 3;
switch (c) {
case 4:
let c = 5;
break;
}
}
```

Expected: should be accepted

Actual:
JSC_REFERENCE_BEFORE_DECLARE_ERROR: Illegal variable reference before declaration: c at line 3 character 10
switch (c) {
^

Compiler link:

https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520SIMPLE_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%250Afunction%2520foo()%2520%257B%250A%2520%2520let%2520c%2520%253D%25203%253B%250A%2520%2520switch%2520(c)%2520%257B%250A%2520%2520%2520%2520case%25204%253A%250A%2520%2520%2520%2520%2520%2520let%2520c%2520%253D%25205%253B%250A%2520%2520%2520%2520%2520%2520break%253B%250A%2520%2520%257D%250A%257D

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.