google / google/closure-compiler

How to annotate a symbol outside the location of definition?

Open
#3,191 4 comments 1 reaction 0 assignees View on GitHub
internal-issue-created triage-done
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

When developing Closure minification support to Emscripten compiler, there is a need to annotate some symbols with e.g. `@suppress {undefinedVars}` or `@suppress {duplicate}`.

If I use an `--externs` file to specify an annotation, e.g. `--externs externs.js`, with

```js
/**
* @suppress {duplicate}
*/
var foo;
```

then not only does Closure take in the annotation, but it also then will no longer minify `foo`, because it is being specified in an externs file.

If I use a `--js` file before the main JS file to specify an annotation, e.g. `--js annotation.js --js main.js`, with

```js
/**
* @suppress {duplicate}
*/
var foo;
```

then Closure will want to add (in some scenarios, not quite sure when this occurs) a top level global dummy variable `var a;` in the beginning of the Closured output file, that takes up redundant space and bloats the final output.

What I'd like to do is specify a `--annotations annotations.js` file that would not prevent minification like externs does, but neither will cause dummy symbols being defined to the build output, like `--js` does. Is this possible somehow with current Closure?

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.