diff --git a/core/blockly.js b/core/blockly.js index 7120e6fb641..56e9e0010a7 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -742,7 +742,24 @@ exports.zelos = zelos; // declareLegacyNamespace only copies normal data properties, not // accessors. This can be removed once all remaining calls to // declareLegacyNamspace have been removed. -if (globalThis.Blockly && typeof globalThis.Blockly === 'object') { +// +// This is only needed in uncompiled mode (see +// google/blockly-samples#902); in compiled mode the exports object is +// already the value of globalThis.Blockly. Because +// closure/goog/base.js is not included in the compiler input, we +// can't use goog.global['COMPILED'] to check if we are running in +// compiled mode. Instead, use existence of globalThis.goog itself +// for this purpose. +// +// Note that this code will still attempt to redefine accessors on a +// previously-imported copy of the Blockly library if both are +// imported in uncompiled mode. This will fail with TypeError as the +// accessors are nonconfigurable (which is good, as otherwise one +// accessors on one copy would call get/set functions on the other +// copy!) +if (globalThis.goog && globalThis.Blockly && + typeof globalThis.Blockly === 'object' && + globalThis.Blockly !== exports) { const descriptors = Object.getOwnPropertyDescriptors(exports); const accessors = {}; for (const key in descriptors) {