You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wanted to make sure there was an issue open here regarding this - was unsure if this was a bug until I saw Chad's comments on this SO thread.
EDIT: I found a few closed issues on this after searching, but it seems like the solution is more of a workaround involving goog.module and goog.define, and I would still consider this to be an open issue (though please feel free to close this if you disagree).
Why it's important to fix
ES6 modules better adhere to DRY principles by allowing developers to export functions with a single keyword, instead of repeatedly redefining everything in module.exports at the bottom of the file. Having just rewritten a codebase into an ES6 module, I was sad to see the only thing preventing it from compiling was the use of a @define flag (the PRODUCTION flag for release builds, which I assume is the most common use case).
The annotation works just fine for CommonJS, but add an import statement and it will stop injecting the variable and display a warning. There's a ready-to-go example repository here, just run ./run.sh.
lib/index.js
/**
* Should be overridden to 42 at compile-time with --define flag.
*
* @define {number}
*/
const TEST_NUMBER = 0;
Closing this because it's a duplicate of #1601 and #2872 and this workaround seems to at least get something to compile as expected. I updated the repo with a workaround.sh to use @shicksgoog.define method and produce meaningful output, old test moved to ./test.sh. As others in the original issue said, @define and -D flags are good to be properly global and overwrite wherever, as the largest use case is likely just for PRODUCTION or RELEASE flags.
For now, replacing a compiler call like google-closure-compiler --define TEST_NUMBER=42 and source like:
/**
* Should be overridden to 42 at compile-time with --define flag.
*
* @define {number}
*/
const TEST_NUMBER = 0;
with google-closure-compiler --define Test.Testing.TestNumber=42 and source like:
/**
* Should be overridden to 42 at compile-time with --define flag.
*
* @define {number}
*/
const TEST_NUMBER = goog.define('Test.Testing.TestNumber', 0);
Will overwrite your variables at compile-time as needed.
Wanted to make sure there was an issue open here regarding this - was unsure if this was a bug until I saw Chad's comments on this SO thread.
EDIT: I found a few closed issues on this after searching, but it seems like the solution is more of a workaround involving
goog.module
andgoog.define
, and I would still consider this to be an open issue (though please feel free to close this if you disagree).Why it's important to fix
ES6 modules better adhere to DRY principles by allowing developers to export functions with a single keyword, instead of repeatedly redefining everything in
module.exports
at the bottom of the file. Having just rewritten a codebase into an ES6 module, I was sad to see the only thing preventing it from compiling was the use of a@define
flag (thePRODUCTION
flag for release builds, which I assume is the most common use case).The annotation works just fine for CommonJS, but add an
import
statement and it will stop injecting the variable and display a warning. There's a ready-to-go example repository here, just run./run.sh
.lib/index.js
command
output
The text was updated successfully, but these errors were encountered: