google / google/closure-compiler
unused function parameter is not eliminated in ADVANCED_OPTIMIZATIONS
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
This issue is pretty hard to reproduce outside of my actual situation so I'm (reluctantly) attaching 4 files (before and after compilation for the bug version and the proper version). [bug.tar.gz](https://github.com/google/closure-compiler/files/525608/bug.tar.gz)
I'm trying to eliminated "verbose" strings in compilation with DEFINEs.
## bug description:
``` js
/**
*
* @param {!Array} keys
* @param {!string|!Array|!boolean|!number} value
* @param {string} key
*/
fillKeys: function (keys, value, key){ // (bug.fingerprint2.js:494)
if (VERBOSE_MODE) {
keys.push({key: key, value: value});
} else {
keys.push(value);
}
}
```
compiles to
``` js
a: function (a, d) { a.push(d) } // (bug.fingerprint2.min.js:200)
```
but the invocations compile to
``` js
z.a(a, 1, "session_storage") // (bug.fingerprint2.min.js:223)
z.a(a, 1, "local_storage") // (bug.fingerprint2.min.js:225)
```
you can clearly see that the last argument is redundant and should be eliminated.
After several attempts to work around this issue, I managed to eliminate the strings.
extracting the `fillKeys` method to a global static function works around it for some reason.
``` js
/**
* @private
* @static
*
* @param {!Array} keys
* @param {!string|!Array|!boolean|!number} value
* @param {string} key
*/
var fillKeys = function (keys, key, value) { // (fingerprint2.js:379)
if (VERBOSE_MODE) {
keys.push({key: key, value: value});
} else {
keys.push(value);
}
};
```
is fully inlined to the invoking lines.
``` js
A.O() && a.push(1) // (fingerprint2.min.js:220)
A.N() && a.push(1) // (fingerprint2.min.js:222)
```
Contributor guide
Assessment
This issue has not been assessed yet.