Don't monkey-patch Blocky.utils.xml.document (#5461)

Use Blockly.utils.xml.setDocument instead.
This commit is contained in:
Christopher Allen
2021-09-14 19:55:31 +01:00
committed by GitHub
parent f4430e9e47
commit d202ae0201
4 changed files with 42 additions and 22 deletions

View File

@@ -32,7 +32,7 @@ const renamings = {
export: 'conditionalBind',
},
},
}
},
},
'6.20210701.0': {
'Blockly': {
@@ -70,14 +70,21 @@ const renamings = {
'Blockly.utils': {
exports: {
genUid: {module: 'Blockly.utils.idGenerator'},
}
},
},
'Blockly.utils.global': {
export: 'globalThis', // Previous default export now named.
},
'Blockly.utils.IdGenerator': {
module: 'Blockly.utils.idGenerator',
}
},
'Blockly.utils.xml': {
exports: {
// document was a function before, too - not a static property
// or get accessor.
document: {export: 'getDocument'},
},
},
},
};

View File

@@ -24,11 +24,10 @@ Blockly.setLocale = function (locale) {
// 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() {
return doc;
};
const jsdom = require('jsdom/lib/jsdom/living');
globalThis.DOMParser = jsdom.DOMParser;
globalThis.XMLSerializer = jsdom.XMLSerializer;
const xmlDocument = Blockly.utils.xml.textToDomDocument(
`<xml xmlns="${Blockly.utils.xml.NAME_SPACE}"></xml>`);
Blockly.utils.xml.setDocument(xmlDocument);
}