mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
fix: Don't kludge accessors in compiled mode (#5591)
In compiled mode we don't need to add exports to the global Blockly object because they'll already be there - and attempting to do so causes problems when a project imports multiple separate copies of Blockly (which it shouldn't, but many plugins do). This is part of the fix for google/blockly-samples#902.
This commit is contained in:
committed by
GitHub
parent
90b3f75d82
commit
56d4fbb39f
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user