Webpack and Gulp plugins don't read jsCode/externs file content
DIYgod opened this issue · 3 comments
There is my configurations and files, the flag externs
works in gulp-closure-compiler
, but doesn't work in closure-compiler-js
.
gulp configuration:
https://github.com/DIYgod/demo/blob/master/bad-closure-compiler-js/gulpfile.js
externs file
https://github.com/DIYgod/demo/blob/master/bad-closure-compiler-js/externs.js
...
var DIYgod;
source file:
var DIYgod = 'cat';
console.log(DIYgod);
gulp-closure-compiler output:
var DIYgod="cat";console.log(DIYgod);
closure-compiler-js output:
console.log("cat");
There is a minimal demo project of this problem, you can also try it yourself, thanks!
Thanks for the bugreport and repro case. I do appreciate that Java and JS should do the same thing. It looks like the Gulp and Webpack plugins actually never read the specified externs. For now, you should pass them in as part of the source (annotated with @externs
, as you're doing).
However I believe you're relying on undefined behavior. When I change the warning level to DEFAULT or VERBOSE on either JS/Java, I get an error. The DIYgod
variable is a const extern—we don't expect it to be declared in your code at all.
Read this for more information: https://developers.google.com/closure/compiler/docs/api-tutorial3#no
@DIYgod
I came across the same issue, and I fixed it by reading extern files by myself before passing 'options' to compiler, as it does in cmd.js of closure compiler.
you can check my gist https://gist.github.com/sunzhuoshi/86f2d5a7f3330e227762b0909372ca60
This is fixed in the main distribution. Please switch to using it insead.