Migrate core.global.js to named exports (#5451)

This is part of #5153 but is being prioritised because we want remove
the declareLegacyNamespace calls from the core/utils/*.js modules and
then reexport them explicitly via utils.js, and it turns out that
doing so results in the exports object of this module being passed to
Object.freeze - which fails on the global object, which can't be made
non-extensible!

The new name chosen for the former default export is globalThis, since
it is intended to have the same value as the global variable of that
name; see:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
This commit is contained in:
Christopher Allen
2021-09-14 14:39:29 +01:00
committed by GitHub
parent 09fb59f6ee
commit f9d0caa112
11 changed files with 38 additions and 33 deletions

View File

@@ -72,6 +72,9 @@ const renamings = {
genUid: {module: 'Blockly.utils.idGenerator'},
}
},
'Blockly.utils.global': {
export: 'globalThis', // Previous default export now named.
},
'Blockly.utils.IdGenerator': {
module: 'Blockly.utils.idGenerator',
}

View File

@@ -22,9 +22,10 @@ Blockly.setLocale = function (locale) {
// Override textToDomDocument and provide Node.js alternatives to DOMParser and
// XMLSerializer.
if (typeof Blockly.utils.global.document !== 'object') {
Blockly.utils.global.DOMParser = require('jsdom/lib/jsdom/living').DOMParser;
Blockly.utils.global.XMLSerializer = require('jsdom/lib/jsdom/living').XMLSerializer;
const globalThis = Blockly.utils.global.globalThis;
if (typeof globalThis.document !== 'object') {
globalThis.DOMParser = require('jsdom/lib/jsdom/living').DOMParser;
globalThis.XMLSerializer = require('jsdom/lib/jsdom/living').XMLSerializer;
var doc = Blockly.utils.xml.textToDomDocument(
'<xml xmlns="https://developers.google.com/blockly/xml"></xml>');
Blockly.utils.xml.document = function() {