google / google/closure-compiler
Non-top-level functions compiled incorrectly
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
With SIMPLE_OPTMIZATIONS,
``` javascript
if (!Math.PI) {
function foo() {}
}
foo();
```
compiles to
``` javascript
if(!Math.PI)var foo=function(){};foo();
```
The original runs without error in all major browsers; the second does not.
Plus, it could even be longer than the original (if you had already removed whitespace and braces).
It should output
``` javascript
if(!Math.PI)function foo(){};foo();
```
(You could also move the function declaration to the top of the scope, but probably not with `SIMPLE_OPTIMIZATIONS`, and in `ADVANCED_OPTIMIZATIONS`, `foo` will be inlined anyway.)
Perhaps someone tried to make the output compatible with ES5 strict?
Contributor guide
Assessment
This issue has not been assessed yet.