Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

goog.module is a new way to define Closure namespaces: https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide

It is used for example in https://github.com/google/incremental-dom

I didn't do full check of how Closure libraries are handled, but one function which is definitely used by {{cljs.closure}} is {{cljs.js-deps/find-classpath-lib}} which calls {{cljs.js-deps/parse-js-ns}} to read a JS file and parse module information from it. Currently the function reads lines before first function declaration and uses a regex to find {{goog.provide}} and {{goog.require}} calls. Probably Closure Compiler has some built-in functionality to parse files which could be leveraged.

Besides reading module information from files, another question is if using {{goog.module}} defined namespaces for traditional/legacy namespaces generated by ClojureScript compiler needs something special. When {{goog.module}} is required, {{goog.require}} returns the exported object but no global is set. There is however a function to create the globals: https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide#how-do-i-use-a-googmodule-from-a-traditional-closure-file


  • Can we still assume that goog.requires all occur before first function declaration?
    -- Would be fixed by using possible Closure Compiler functionality
    -- Class {{com.google.javascript.jscomp.deps.JsFileParser}} looks promising
  • "GCL hasn't switched to it so it may be something driven by some users not something that Google uses more broadly" (David at slack)

1 Answer

0 votes
Reference: https://clojure.atlassian.net/browse/CLJS-1543 (reported by deraen)