google / google/closure-compiler

Unable to use @define with window property

Open
#2,217 1 comment 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

Given this `main.js` script:
```js
/**
* @define {boolean} Enable debug mode. Default is `true`.
*/
window.DEBUG = true;

if (window.DEBUG) {
alert('failure');
} else {
alert('success');
}
```

I would expect to be able to run the compiler with `window.DEBUG=false` and have the resulting script `alert('success')`.

Instead, I get `WARNING - unknown @define variable window.DEBUG`. See below for the full output:
```
$ java -jar closure-compiler-v20161201.jar -D "window.DEBUG=false" --js main.js
WARNING - unknown @define variable window.DEBUG

0 error(s), 1 warning(s)
window.DEBUG=!0;window.DEBUG?alert("failure"):alert("success");
```

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.