From 06a41de61e776a64b4ef7cff727aed679d1ce6f5 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Mon, 27 Sep 2021 17:51:59 +0100 Subject: [PATCH] fix: Add hack to copy accessors to global Blockly namespace object (#5536) Ugly, but it works. --- core/blockly.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/blockly.js b/core/blockly.js index a02835e1a..c39ae3e79 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -159,6 +159,7 @@ const {BlockSvg} = goog.require('Blockly.BlockSvg'); const {Blocks} = goog.require('Blockly.blocks'); const {ConnectionType} = goog.require('Blockly.ConnectionType'); const {Cursor} = goog.require('Blockly.Cursor'); +const {globalThis} = goog.require('Blockly.utils.global'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockCreate'); /** @suppress {extraRequire} */ @@ -673,3 +674,20 @@ exports.thrasos = thrasos; exports.uiPosition = uiPosition; exports.utils = utils; exports.zelos = zelos; + +// Temporary hack to copy accessor properties from exports to the +// global Blockly object as the routine to copy exports in +// goog.exportPath_ (see closure/goog/base.js) invoked by +// 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') { + const descriptors = Object.getOwnPropertyDescriptors(exports); + const accessors = {}; + for (const key in descriptors) { + if (descriptors[key].get || descriptors[key].set) { + accessors[key] = descriptors[key]; + } + } + Object.defineProperties(globalThis.Blockly, accessors); +}