How eliminate JSC_INVALID_FORWARD_DECLARE errors compiling google closure library files? - google-closure-compiler

Coming back to a project after several years, I am struggling with changes to Google closure compilation. I am using a fresh download of the closure library from github, and these tools:
java version "1.8.0_152"
Closure compiler Version: v20200830
With the script quoted below, I get seventeen errors like this, all on closure library files (the only ones I am trying for now):
js/closure-library/closure/goog/net/browsertestchannel.js:20:0:
ERROR -[JSC_INVALID_FORWARD_DECLARE] Malformed goog.forwardDeclare
20| goog.forwardDeclare('goog.net.BrowserChannel');
The script:
java -jar closure-compiler-v20200830.jar
--language_in ECMASCRIPT_NEXT
--language_out ECMASCRIPT5
--js js/closure-library/closure/goog/debug/**.js
--js js/closure-library/closure/goog/log/**.js
--js js/closure-library/closure/goog/testing/**.js
--js js/closure-library/closure/goog/testing/events/**.js
--js js/closure-library/closure/goog/testing/ui/**.js
--js js/closure-library/closure/goog/testing/net/**.js
--js js/closure-library/closure/goog/testing/net/rpc/**.js
--js js/closure-library/closure/goog/array/**.js
--js js/closure-library/closure/goog/asserts/**.js
--js js/closure-library/closure/goog/string/**.js
--js js/closure-library/closure/goog/reflect/**.js
--js js/closure-library/closure/goog/userAgent/**.js
--js js/closure-library/closure/goog/dom/**.js
--js js/closure-library/closure/goog/dom/browserrange/**.js
--js js/closure-library/closure/goog/dom/animationframe/**.js
--js js/closure-library/closure/goog/html/**.js
--js js/closure-library/closure/goog/html/sanitizer/**.js
--js js/closure-library/closure/goog/structs/**.js
--js js/closure-library/closure/goog/style/**.js
--js js/closure-library/closure/goog/Promise/**.js
--js js/closure-library/closure/goog/events/**.js
--js js/closure-library/closure/goog/net/**.js
--js js/closure-library/closure/goog/net/rpc/**.js
--js js/closure-library/closure/goog/object/**.js
--js js/closure-library/closure/goog/uri/**.js
--js js/closure-library/closure/goog/functions/**.js
--js js/closure-library/closure/goog/async/**.js
--js js/closure-library/closure/goog/ui/**.js
--js js/closure-library/closure/goog/Timer/**.js
--js js/closure-library/closure/goog/json/**.js
--js js/closure-library/closure/goog/iter/**.js
--js js/closure-library/closure/goog/math/**.js
--js js/closure-library/closure/goog/Disposable/**.js
--js js/closure-library/closure/goog/labs/**.js
--js js/closure-library/closure/goog/dispose/**.js
--js js/closure-library/closure/goog/window/**.js
--js js/closure-library/closure/goog/a11y/**.js
--js js/closure-library/closure/goog/positioning/**.js
--js js/closure-library/closure/goog/date/**.js
--js js/closure-library/closure/goog/spell/**.js
--js js/closure-library/closure/goog/graphics/**.js
--js js/closure-library/closure/goog/fx/**.js
--js js/closure-library/closure/goog/fx/anim/**.js
--js js/closure-library/closure/goog/color/**.js
--js js/closure-library/closure/goog/i18n/**.js
--js js/closure-library/closure/goog/i18n/uChar/**.js
--js js/closure-library/closure/goog/fx/css3/**.js
--js js/closure-library/closure/goog/fs/**.js
--js js/closure-library/closure/goog/fs/url/**.js
--js js/closure-library/closure/goog/fs/blob/**.js
--js js/closure-library/closure/goog/memoize/**.js
--js js/closure-library/closure/goog/pubsub/**.js
--js js/closure-library/closure/goog/storage/**.js
--js js/closure-library/closure/goog/storage/mechanism/**.js
--js js/closure-library/closure/goog/testing/storage/**.js
--js js/closure-library/closure/goog/testing/fs/**.js
--js js/closure-library/closure/goog/crypt/**.js
--js js/closure-library/closure/goog/crypt/hash32/**.js
--js js/closure-library/third_party/closure/goog/mochikit/async/deferred.js
--compilation_level SIMPLE
--warning_level QUIET
--formatting PRETTY_PRINT
--checks_only
--third_party
--js_output_file dist/quickgoog.js
I am guessing that, because these are google closure's own files, I must have some options backwards, but the google is not offering anything on this specific error. Any advice welcome!

I was able to reproduce your error, and for some reason removing the third_party flag allows me to compile Closure Library successfully. I don't think this is correct, and think you should file a bug on the Closure Compiler Github: https://github.com/google/closure-compiler/issues

Related

Jigsaw cannot create a modular JAR with the jar tool

I am using the build 9-ea+129-jigsaw-nightly-h5332-20160730
I have a very simple module with a Main class and a module-info.java
I compile the module using javac --module-source-path and everything is ok. The class files are being generated for both module-info.class and Main.class
javac -d modules --module-source-path src $(find . -name "*.java")
When I try to create the modular JAR file with the jar tool, I get the following error message:
module-info.class found in a versioned directory without module-info.class in the root
My module-info.class is there in the root directory.
I run:
$ jar --create --file mlib/ModuleFirst#1.0.jar --module-version 1.0 --main-class com.firstmodule.Main -c modules/com.firstmodule
Can you tell me why do I get this error and what I did wrong?
Thank you
Regards
I have the same problem
You should change a lot your command
$ jar --create --file mlib/ModuleFirst#1.0.jar --module-version 1.0 --main-class com.firstmodule.Main -C modules/com.firstmodule .
You must use the capital C and put the dot at the end of line

closure compiler output on the same file not working [duplicate]

This question already has answers here:
Use Closure Compiler Command Line Minify and Replace Original File
(2 answers)
Closed 8 years ago.
I try to override my source file with compiled version at build time.
java -jar compiler.jar --js test.js --js_output_file test.js
the above command succeed but the content of test.js gets wipped out.
If I output to a different file then it works.
What should i do to make it override the same file with minified
version?
try:
java -jar compiler.jar --js test.js > test2.js; mv test2.js test.js

Getting started with JavaCC

I am new to JavaCC and cannot figure out how to get it running. I am using Mac OS X and I installed javacc-6.0.zip and unzipped it. I am unable to make the javacc script accessible from my path as on typing javacc on the terminal I get the following message:
-bash: javacc: command not found
How do I make the javacc script accessible from my path?
My unzipped folder javacc-6.0 is in the following directory: /Users/Rishabh/Desktop/javacc
So I do the following on the terminal:
PATH=$PATH\:/Users/Rishabh/Desktop/javacc/javacc-6.0/
Typing javacc next gives me the same message.
The version of JavaCC 6.0 that I downloaded today (2013.07.22) did not have a complete bin directory. It was missing all the script files! Hopefully this will be remedied soon.
For OS X and other unix/linux variants, the missing script file is called javacc, should be executable, and should contain the following:
#!/bin/sh
JAR="`dirname $0`/lib/javacc.jar"
case "`uname`" in
CYGWIN*) JAR="`cygpath --windows -- "$JAR"`" ;;
esac
java -classpath "$JAR" javacc "$#"
Add the bin directory to your PATH (omitting the backslash -- as pointed out by Ahmed Masud) and all should be ticketty boo. If your OS comes from Redmond or you want to run jjtree or jjdoc, just download javacc-5.0 and copy the script files (NOT the lib directory!!!!) from the 5.0 bin directory to the 6.0 bin directory.
Update (2020): Since version 6 is now harder to find, I have put a copy at www.engr.mun.ca/~theo/JavaCC/javacc-6.1.0.zip
In Windows, I also had no javacc and have to use
java -cp bin\lib\javacc.jar javacc
instead. This is very frustrating because all docs propose to use javacc, which we miss. Yet, I see that javacc was defined in the old javacc 5.0. I see javacc.bat there
java -classpath "%~dp0lib\javacc.jar;%~dp0lib\javacc.jar;%~f0\..\lib\javacc.jar" javacc %1 %2 %3 %4 %5 %6 %7 %8 %9
more javacc:
#!/bin/sh JAR="`dirname $0`/lib/javacc.jar"
case "`uname`" in
CYGWIN*) JAR="`cygpath --windows -- "$JAR"`" ;; esac
java -classpath "$JAR" javacc "$#"
more jjtree:
#!/bin/sh JAR="`dirname $0`/lib/javacc.jar"
case "`uname`" in
CYGWIN*) JAR="`cygpath --windows -- "$JAR"`" ;; esac
java -classpath "$JAR" jjtree "$#"
Create these scripts in the bin folder of your javacc-6.0/bin.
make a chmod :
chmod 755 javacc
chmod 755 jjtree
On Mac OS X & Linux I just use a single script and two symbolic links:
echo 'java -cp /path/to/javacc.jar $(basename $0) "$#"' > javacc
chmod 755 javacc
ln -s javacc jjtree
ln -s javacc jjdoc
The first two lines create the script and make it executable.
The second two lines reuse the javacc script for jjtree and jjdoc, since it all comes from the same JAR.
You need to first unzip the package, and add location where your javacc is located in your
PATH environment variable.
like:
set path=%path%;<location_of_your_javacc>;
Check if you have javacc and jjtree in the bin/ directory of your javacc-6.0.zip. When you get javacc6.0 from https://javacc.java.net/, this bin directory is empty.
javacc & jjtree are scripts.
Actually i'm using Java 5.0 and i'm modified my .profile file to add (I put javacc in my Applications folder):
export
PATH=/opt/local/bin:/opt/local/sbin:/Applications/javacc-5.0/bin/:$PATH
It's working perfectly.

How to compile several files to the same ones

I know that Google Closure Compiler allows me to compile several files into a single one like the following:
java -jar compiler.jar --js assets/js/file1.js
assets/js/file2.js --js_output_file assets/js/file.min.js
But I need to compile files and put it to the same name in the same folder like this:
java -jar compiler.jar --js assets/js/file1.js
--js_output_file assets/js/file1.js
java -jar compiler.jar --js assets/js/file2.js
--js_output_file assets/js/file2.js
But it doesn't work. The files get corrupted. Can you help me?
First and most importantly, your compile script is set up to overwrite your source files. Are you really, absolutely positive that this is what you intend to do? Compilation is a lossy transformation: it destroys comments (including type annotations), renames everything, refactors aggressively, inlines everywhere, and generally purees your hard work into an unmaintainable mess.
java -jar compiler.jar --js assets/js/file1.js
--js_output_file assets/js/file1.js
java -jar compiler.jar --js assets/js/file2.js
--js_output_file assets/js/file2.js
If I am to take you at your word and you have actually done the above, this would unfortunately explain your "my files are now corrupted" question. I hope you have a backup.
More generally, grok the Compiler Manual. All of it, but especially the section on inconsistent property names. If the compiler is not informed about how your source files relate to eachother, it is impossible for closure to rename their contents consistently.
If you intend to create pre-compiled .dll style shared objects, this is not supported by closure because of the name-fragmentation issues documented in the manual. Also, there's no need to pre-compile, compilation is reasonably fast as-is. Share your source files instead.
Please, please make yourself a build directory and pipe your compiler output away from your source code. Code never builds perfectly on the first pass. Even if the code in question is a simple math utility, you'll want to build and test more than a few times.
In summary:
(1) read entire manual, (2) write Externs or try goog.require, (3) pre-compilation is overrated, (4) never ever ever overwrite source files ever, (5) keep frequent backups.
Simply use multiple "--js" params in command line:
java -jar compiler.jar --js 1.js --js 2.js --js 3.js --js_output_file all.js

Using the --module option in Closure Compiler to create multiple output files

I'm creating a fairly large library of JavaScript, using Closure Compiler for both its wonderful compression as well as the type-checking and warning systems.
I want to create multiple output files though, because the files are loaded asynchronously (and some files are only loaded on-demand).
Poking around the source code, I've found the --module flag, as well as some related flags. The source code says the following about the option:
A javascript module specification. The format is <name>:<num-js-files>[:[<dep>,...][:]]]. Module names must be unique. Each dep is the name of a module that this module depends on. Modules must be listed in dependency order, and js source files must be listed in the corresponding order. Where --module flags occur in relation to --js flags is unimportant
... and that's all I can find. I'd love to learn more about how to use this option, does anyone have any experience here? Alternatively, if there's another way to create multiple output files, I'm all ears.
java -jar compiler.jar ^
--chunk jq:1: --js jquery-1.6.2.js ^
--chunk t:1:jq: --js test.js ^
--compilation_level ADVANCED_OPTIMIZATIONS
This example will compile out 2 files for you:
jq.js
t.js
jq.js will be jquery 1.6.2 with advanced minification, and t.js will use that minified version of JQuery properly.
I wish there was a JavaFiddle I could post this to to demonstrate it.
Older version
This original answer was for an older version of Closure Compiler. I've left it intact below in case you're in an environment that needs to keep the older version in place.
How to handle multiple output files, aka modules:
http://groups.google.com/group/closure-compiler-discuss/browse_thread/thread/ec7f6809b19b019e/25a94f3994173840
Copy/pasting:
java -jar Build\Tools\compiler.jar ^
--compilation_level=ADVANCED_OPTIMIZATIONS ^
--externs Build\jQuery.externs.js ^
--js Build\Output\Compiling.js ^
--js Script/Themes.lang.js ^
--js Script/Themes.js ^
--module Core:3 ^
--js UI/ThemeChooser/ThemeChooser_en.htm.js ^
--js UI/ThemeChooser/ThemeChooser.js ^
--module UI_ThemeChooser:2:Core ^
--js UI/VerticalTabs/VerticalTabs_en.htm.js ^
--js UI/VerticalTabs/VerticalTabs.js ^
--module UI_VerticalTabs:2:Core ^
--js Pager/Pager_en.htm.js ^
--js Pager/jquery.Pager.js ^
--js Pager/Pager.js ^
--module Pager:3:VerticalTabs ^
--module_output_path_prefix .\Compiled\
And as he notes, --js_output_file is irrelevant when outputting modules.
Note: Apparently the Closure Compiler has changed the arg "--module" to "--chunk". An editor suggested the change; for the newer version I kept the change, for the older version I kept the older argument name, since there are always people out there using older versions of build tools, and that kind of small breaking change can really screw ya up.

Resources