google / google/closure-compiler
Compiler doesn't remove unreachable branches
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
This can be a limitation of the compiler.
Input:
```
const flags = {
"enabled": false
};
if (!flags["enabled"]) {
console.log("not enabled");
} else {
console.log("enabled");
}
if (flags["otherOption"]) {
console.log("other option");
}
```
Command:
```
java -jar node_modules/google-closure-compiler/compiler.jar --entry_point input.js \
--compilation_level ADVANCED_OPTIMIZATIONS \
--isolation_mode IIFE input.js
```
Output:
```
(function(){var a={enabled:!1};a.enabled?console.log("enabled"):console.log("not enabled");a.otherOption&&console.log("other option");}).call(this);
```
I would expect the output to only contain one console.log as other branches are unreachable.
Is this not possible, e.g. is it unable to determine these conditions in compilation time?
Contributor guide
Assessment
This issue has not been assessed yet.