google / google/closure-compiler

Shadowed globals throw duplicate declaration error

Open
#3,098 9 comments 0 reactions 0 assignees View on GitHub
internal-issue-created triage-done
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

The following code throws an error:
```js
const Worker = 'foo';
```
For reference, here's what the error looks like:
```
stdin:1: ERROR - Duplicate let / const / class / function declaration in the same scope is not allowed.
const Worker = 'foo';
^^^^^^^^^^^^^^

1 error(s), 0 warning(s)
```
The same error is producible with any other global. I'm pretty sure it's not an error to shadow globals in JS, regardless of the environment (i.e. it's part of the ECMAScript spec).

I think the culprit is in the way `externs` are defined. Since they're functions, the compiler treats this situation as a redeclaration.

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.