google / google/closure-compiler

Different behavior when inlining anonymous functions?

Open
#1,349 5 comments 0 reactions 0 assignees View on GitHub
OTI P3
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

I use ADVANCED optimization and I expect both scripts to raise a warning because of bad callFn argument.

This script raises a warning:

``` javascript
/**
* @param {function(number)} fn
*/
function callFn(fn) {
fn(1);
};

var fnToCall = function (/** !Function */ arg) {
console.log(arg);
};

callFn(fnToCall);
```

This does not (fnToCall inlined):

``` javascript
/**
* @param {function(number)} fn
*/
function callFn(fn) {
fn(1);
};

callFn(function fnToCall(/** !Function */ arg) {
console.log(arg);
});
```

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.