fix(closure): Make safe to import in node.js

Make the implementation declareModlueId safe to import and
execute in node.js, which does not provide a window global.

(N.B. because this is an ESM and therefore automatically
strict, using window?.goog?.declareModuleId doesn't work
because window being undefined is an early error.)
This commit is contained in:
Christopher Allen
2023-08-10 12:21:27 +01:00
parent 8bb6ac528b
commit cf460dcde0

View File

@@ -72,9 +72,9 @@ export const global = globalThis;
// export const scope = goog.scope;
// export const defineClass = goog.defineClass;
export const declareModuleId = function(namespace) {
if (window.goog && window.goog.declareModuleId) {
window.goog.declareModuleId.call(this, namespace);
}
// Use globalThis instead of window to find goog, so this can be
// imported in node.js (e.g. when running buildShims gulp task).
globalThis?.goog?.declareModuleId.call(this, namespace);
};