google / google/closure-compiler

@suppress part of function?

Open
#679 9 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

I'm having a really hard time suppressing portions of functions.

I've committed some code to Chrome recently[1] that uses an API not yet in the global externs (which I'm in the process of updating), but is breaking our compile in the meantime[2]. I'd like to `@suppress` only the lines that use this new API, but I can't figure out how to locally `@suppress` things.

I've tried:

``` js
/** @suppress {checkTypes} */
var link = document.createElement('a', 'action-link');

var link;
/** @suppress {checkTypes} */
(function() {
link = document.createElement('a', 'action-link');
}());

var link;
(/** @suppress {checkTypes} */ function() {
link = document.createElement('a', 'action-link');
}());

var link = /** @suppress {checkTypes} */ function() {
return document.createElement('a', 'action-link');
}();
```

... and none of them work.

I've resorted to making named function expressions just to get around this:

``` js
/** @suppress {checkTypes} */
var makeLink = function() { return document.createElement('a', 'action-link'); };
var link = makeLink();
```

which works but is a total bummer.

[1] https://codereview.chromium.org/674203006/
[2] http://build.chromium.org/p/chromium.fyi/builders/Closure%20Compilation%20Linux

/cc @MatrixFrog

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.