From cf460dcde07263cbb55c70310456b433961584e6 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Thu, 10 Aug 2023 12:21:27 +0100 Subject: [PATCH] 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.) --- closure/goog/goog.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/closure/goog/goog.js b/closure/goog/goog.js index 6e81b6987..f044ececb 100644 --- a/closure/goog/goog.js +++ b/closure/goog/goog.js @@ -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); };