forked from RaspberryPiFoundation/blockly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap_helper.js
More file actions
73 lines (66 loc) · 2.29 KB
/
Copy pathbootstrap_helper.js
File metadata and controls
73 lines (66 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @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/messages.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);
// This is a kludge to work around an issue where attempting to
// load Blockly.libraryBlocks (blocks/blocks.js) fails if the
// Blockly global variable is not defined.
//
// This is apparently because the debug module loader fails to
// load Blockly.libraryBlocks.lists (blocks/lists.js) and
// .procedures (blocks/procedures.js) first, despite they both
// being required from blocks.js, and that is apparently because
// they both depend on Blockly.Xml which the debug loader seems
// to think has not been loaded yet even though it has.
if (require === 'Blockly') {
window.Blockly = goog.module.get('Blockly');
}
}
}
// 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;
}
})();