google / google/closure-compiler
Disambiguation clobbers weirdly-named properties
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
[Repro]
```js
/** @constructor */
function Foo() {
this.bar = 42;
}
Foo.bar = 0; // this is just to force disambiguation to happen
new Foo().Foo$bar = 53;
```
disambiguates to
```js
/** @constructor */ function Foo() {
this.Foo$bar = 42;
}
Foo.function_new_Foo___undefined$bar = 0; // ignore me
(new Foo).Foo$bar = 53; // clobbers the disambiguated name
```
This is, admittedly, a contrived example, but the compiler has changed the behavior of completely valid JS code, so I would consider this a bug. The workaround is that we need to keep a set of all property names (either renamed or not) and add some sort of extra suffix in any cases where there would be a collision. Since we update all instances of a property at the same time, this should be doable.
[Repro]: https://closure-compiler-debugger.appspot.com/#input0%3D%252F**%2520%2540constructor%2520*%252F%250Afunction%2520Foo()%2520%257B%250A%2520%2520this.bar%2520%253D%252042%253B%250A%257D%250AFoo.bar%2520%253D%25200%253B%250Anew%2520Foo().Foo%2524bar%2520%253D%252053%253B%26input1%26conformanceConfig%26externs%26refasterjs-template%26CHECK_SYMBOLS%3Dtrue%26MISSING_PROPERTIES%3Dtrue%26TRANSPILE%3Dtrue%26CHECK_TYPES%3Dtrue%26DISAMBIGUATE_PROPERTIES%3Dtrue%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue
Contributor guide
Assessment
This issue has not been assessed yet.