Files
blockly/tests/bootstrap_helper.js
Christopher Allen d83dcfbe2e chore(build,tests): Remove obsolete kludges / config options (#6835)
* chore(tests): Remove circular import loading issue kludge

  Prior to PR #6818, circular imports resulted in the debug module
  loader (in closure/goog/base.js) failing to record the
  goog.module ID of most modules that were
  involved in the cycle, and in particular of the Blockly.Xml
  module.  This had secondary fallout that resulted
  in library blocks modules being loaded in the wrong order.

  A kludge was introduced in PR #6703 that worked around this
  problem by making sure that window.Blockly was set, allowing
  the modules loaded out-of-order to still work.

  Now that we have removed all remaining circular dependencies
  there is no need for the kludge, since all module IDs are
  properly recorded and modules are loaded in the correct order.

* chore(build): Remove exclude for non-existent core/blockly.js

  There was a transitional period where we had both
  core/blockly.ts and core/blockly.js, and wished to exclude
  the latter from tsc's input, but the latter file was deleted
  (and inadvertently restored, then re-deleted) some time ago.
2023-02-08 11:56:35 +01:00

60 lines
1.6 KiB
JavaScript

/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Helper script for bootstrap.js
*
* This is loaded, via goog.bootstrap(), after the other top-level
* Blockly modules. It simply calls goog.require() for each of them,
* to force the debug module loader to finish loading them before any
* non-module scripts (like msg/en.js) that might have
* undeclared dependencies on them.
*/
(function() {
const info = window.bootstrapInfo;
if (!info.compressed) {
// Force debug module loader to finish loading all modules.
for (const require of info.requires) {
goog.require(require);
}
}
// Create global names for named and destructured imports.
for (const varName in info.namedImports) {
const id = info.namedImports[varName];
const value = info.compressed ? get(id) : goog.module.get(id);
if (value) {
window[varName] = value;
}
}
for (const varName in info.destructuredImports) {
const id = info.destructuredImports[varName];
const value = info.compressed ? get(id) : goog.module.get(id)[varName];
if (value) {
window[varName] = value;
}
}
return; // All done. Only helper functions after this point.
/**
* Get the object referred to by a doted-itentifier path
* (e.g. foo.bar.baz).
* @param {string} path The path referring to the object.
* @return {string|null} The object, or null if not found.
*/
function get(path) {
let obj = window;
for (const part of path.split('.')) {
obj = obj[part];
if (!obj) return null;
}
return obj;
}
})();