google / google/closure-compiler
Local functions are wrongly made global in Strict mode
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
When strict mode is enabled, the following code triggers an error for the second call to `func1`:
```
'use strict';
{
function func1(arg){ //func1 is local to the scope, not global
alert(arg) ;
}
func1('Hi') ;
}
func1('Hi') ; // <-- Error: func1 does not exist globally
```
When we compile that code:
```
java -jar closure-compiler-v20190121.jar --language_out NO_TRANSPILE -O SIMPLE --js_output_file Output.js Input.js
```
We get:
```
'use strict';
var func1 = function(a) {
alert(a);
};
func1("Hi");
func1("Hi");
```
i.e. `func1` was converted to a global function, which makes the code behave different than the original.
Contributor guide
Assessment
This issue has not been assessed yet.