google / google/closure-compiler
Name collision between properties and global variables
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
When the following code snippet is compiled with `ADVANCED_OPTIMIZATIONS`
```
function f(node) {
node.foo = null;
}
console.log(f); // to prevent inlining
f(window);
f(window);
```
both `f` and `foo` get renamed to `a`:
```
function a(b){b.a=null}console.log(a);a(window);a(window);
```
causing a JavaScript error at the second `f(window)` call.
Is it possible to robustly prevent such name collisions?
Background: when the D3.js library registers a listener on an event target (such as a window), it [sets the target.__on property](https://github.com/d3/d3-selection/blob/master/src/selection/on.js#L72) potentially overwriting a global symbol that happen to got renamed to the same thing.
Contributor guide
Assessment
This issue has not been assessed yet.