google / google/closure-compiler
missed property collapsing opportunity
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
If I run the following code through advanced optimization, I can still see the debug statements in the code.
``` js
var log = console.info.bind(console);
(function() {
/** @const */
var DEBUG = false;
log('Brady', createRank({
max: 100,
debug: DEBUG
}));
})();
function createRank(options) {
if (options.debug) {
log('This should be in debug mode only');
}
if (typeof alert == 'function') {
alert(options);
}
return (Math.random() * options.max) | 0;
}
```
output after Advanced compilation:
``` js
(function() {
var a = console.info.bind(console),
b = {
max: 100,
debug: !1
};
b.debug && a("This should be in debug mode only");
"function" == typeof alert && alert(b);
a("Brady", Math.random() * b.max | 0);
})();
```
Is this not meant to be removed ? Also would you know if there is any other way of getting rid of debug message with advanced mode ?
If DEBUG is global, and logging statements are enclosed like:
``` js
if (DEBUG) {
log('debug message');
}
```
then it would work but is there a way to make it work if we don't not want it as a global variable, and rather pass the value around to individual modules/functions via parameters.
Contributor guide
Assessment
This issue has not been assessed yet.