Files
blockly/tests/bootstrap_done.mjs
Christopher Allen 9e69fa9491 refactor(tests): Rename blockly.mjs to bootstrap_done.mjs; simplify
Since blockly.mjs is no longer returning just the exports object
from core/blockly.js (see PR #5995), it might be better named after
its actual purpose: to wait for bootstrapping to be done.

Remove all the code that was used to pass the blockly.js exports
object along from the bootstrap callback to the blockly.mjs export,
since there's no reason to go to a lot of trouble to set a local
variable named Blockly to the same value as a global variable named
Blockly.

(Something like this may be needed again in future, but certainly in
a different form.)
2022-06-14 23:35:48 +01:00

37 lines
1.3 KiB
JavaScript

/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Finishes loading Blockly and exports it as this
* module's default export.
*
* It is exported as the default export to avoid having to
* re-export each property on Blockly individually, because you
* can't do:
*
* export * from <dynamically computed source>; // SYNTAX ERROR
*
* You must use a <script> tag to load prepare.js first, before
* importing this module in a <script type=module> to obtain the
* loaded value.
*
* See tests/playground.html for example usage.
*/
if (window.BlocklyLoader) {
// Uncompressed mode. Use top-level await
// (https://v8.dev/features/top-level-await) to block loading of
// this module until goog.bootstrap()ping of Blockly is finished.
await window.BlocklyLoader.done;
// Note that this module previously did an export default of the
// value returned by the BlocklyLoader.done promise. This was
// changed in PR #5995 because library blocks and generators cannot
// be accessed via that the core/blockly.js exports object.
} else if (window.Blockly) {
// Compiled mode. Nothing more to do.
} else {
throw new Error('neither window.Blockly nor window.BlocklyLoader found');
}