Closure Compiler + Closure Library usage

250 views
Skip to first unread message

Andriy Romanov

unread,
Jun 30, 2018, 6:43:59 AM6/30/18
to Closure Compiler Discuss
Trying to compile a.js file that has one goog.require('goog.string') and use google closure library. I am probably missing something simple. Here is output I am getting:

aromanov@Thinkpad:~/src/js/closure/first$ java -jar ~/Downloads/compiler-latest/closure-compiler-v20180610.jar --js ../closure-library/closure/goog/ --js a.js
../closure-library/closure/goog/base_module_test.js:145: WARNING - The body of an ES6 module cannot reference this.
      this)
      ^^^^

../closure-library/closure/goog/testing/testrunner_test.js:25: ERROR - Illegal redeclared variable: testCase
let testCase;
    ^^^^^^^^

1 error(s), 1 warning(s)

Are there some additional options that I need to specify? What is the conventional usage of closure compiler with closure library?

ghosttie

unread,
Jun 30, 2018, 8:26:31 AM6/30/18
to Closure Compiler Discuss
I think you're going to need to post more of your code

Chad Killingsworth

unread,
Jun 30, 2018, 8:34:34 AM6/30/18
to Closure Compiler Discuss
Including closure-compiler is kinda a pain. To use globs, you end up excluding a lot of things. However for simple things, you can just include all the needed files (order matters if you don't use the dependency management flags):

java -jar compiler.jar --js ../closure-library/closure/goog/base.js --js  ../closure-library/closure/goog/string/string.js --js=a.js

You definitely don't want to include any file that ends with `_test.js`.

Chad Killingsworth

Andriy Romanov

unread,
Jun 30, 2018, 6:25:45 PM6/30/18
to Closure Compiler Discuss
Here is code from a.js:

goog.require('goog.string')

var someFunction = function() {
  if (goog.string.startsWith('abcd', 'ab')) {
    console.log('It definitely starts')
  }
  return 1+1
}
console.log(someFunction())

Super generic code that just does goog.require. Generally speaking following works:
java -jar ~/Downloads/compiler-latest/closure-compiler-v20180610.jar --js ../closure-library/closure/goog/string/string.js --js a.js
But it kind of defeats the purpose of dependency management. I would love not hvae to manually find all the dependencies and include them.

Chad Killingsworth

unread,
Jun 30, 2018, 6:35:18 PM6/30/18
to Closure Compiler Discuss
Then your compile command is going to look something like:

java -jar compiler.jar \
 
--dependency_mode STRICT \
  --entry_point ./a.js \
 
--js
`../closure-library/closure/**.js' \
    --js '../closure-library/third_party/**.js' \
    --js '!../closure-library/**test.js', \
    --js '!../closure-library/**tester.js' \
    --js `!../closure-library/**_perf.js' \
    --js '!../closure-library/closure/goog/bootstrap/nodejs.js' \
    --js '!../closure-library/closure/goog/bootstrap/bytestring_perf.js' \
    --js a.js

Andriy Romanov

unread,
Jun 30, 2018, 7:25:24 PM6/30/18
to Closure Compiler Discuss
That worked. Thank you
Reply all
Reply to author
Forward
0 new messages