function polyfillDeclareNamespace()

in polymer/lib/utils/boot_bridge.js [29:82]


function polyfillDeclareNamespace() {
  // For code that doesn't compile or use the goog debug loader, we need to stub
  // out goog.declareModuleId
  //
  // We only use it for ordering and strict deps checking, and when loaded
  // uncompiled with pure HTML Imports and ES modules, we don't need either of
  // these.

  // This is a wrapper around goog.declareModuleId that is a no-op if
  // this code is loaded through native ES modules
  // (almost certainly via HTML Imports) rather than the closure debug
  // loader, but should behave exactly the same when compiled.
  // Note that combining HTML Imports with the closure debug loader
  // has never been supported, and would always result in duplicated code.
  // This is introducing another way that this could happen, but hopefully
  // this will not affect anyone who was already working.
  let realDeclareModuleId =
      window.goog && window.goog.declareModuleId || (() => {});
  const lenientDeclareModuleId = function(id) {
    if (!goog.isInEs6ModuleLoader_()) {
      // The real declareNamespace would throw. Don't do that.
      return;
    }
    return realDeclareModuleId(id);
  };

  if (window.goog.declareModuleId) {
    // Closure base already loaded, this is the happy normal case. Just
    // make declareModuleId more lenient.
    goog.declareModuleId = lenientDeclareModuleId;
  } else {
    // Closure base is not loaded. We need to handle two cases here:
    //     - the case where closure base will be loaded later
    //     - the case where Polymer core's usage is the only usage of
    //       closure base in the whole program

    // Bootstrap parts of goog that lenientDeclareModuleId needs.
    window.goog.isInEs6ModuleLoader_ = () => {
      return false;
    };

    // Ensure that declareModuleId is lenient even if goog is loaded
    // later.
    Object.defineProperty(window.goog, 'declareModuleId', {
      get() {
        return lenientDeclareModuleId;
      },
      set(newRealDeclareModuleId) {
        realDeclareModuleId = newRealDeclareModuleId;
        return lenientDeclareModuleId;
      }
    });
  }
}