google / google/closure-compiler

Non-top-level functions compiled incorrectly

Open
#594 6 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.