mirror of
https://github.com/google/blockly.git
synced 2026-01-22 08:17:09 +01:00
fix(deps): Don't use global variables for jsdom injection in scripts/package/node/core.js and core/utils/xml.ts (#6764)
* fix(node): Don't use global variables for jsdom injection
Introduce a (hopefully generally applicable) mechanism for
injecting dependencies into modules, specifically in this case
to inject required bits of JSDOM's Window and Document
implementations into core/utils/xml.js when running in
node.js or other environments lacking a DOM.
The injectDependencies function uses an options object to
facilitate optionally injecting multiple named dependencies
at the same time.
Rename the xmlDocument local variable back to document (was
renamed in #5461) so that the name used in this module
corresponds to the usual global variable it replaces.
Change the injection in scripts/package/node/core.js to use
injectDependencies instead of setXmlDocument + global variables;
also eliminate apparently-unnecessary creation of a special
Document instance, using the default one supplied by jsdom
instead.
Fixes #6725.
* deprecate(xml): Deprecate getXmlDocument and setXmlDocument
Mark getXmlDocument and setXmlDocument as @deprecated, with
suitable calls to deprecation.warn().
There are no remaining callers to either function within core -
setXmlDocument was only used by the node.js wrapper, and and
apparently getXmlDocument was never used AFAICT - and we do not
anticipate that either were used by external developers.
* fix: Corrections for comments on PR #6764.
(cherry picked from commit cd57e74d1a)
This commit is contained in:
committed by
Aaron Dodson
parent
b9e3626966
commit
f6bde95f63
@@ -18,9 +18,5 @@
|
||||
if (typeof globalThis.document !== 'object') {
|
||||
const {JSDOM} = require('jsdom');
|
||||
const {window} = new JSDOM(`<!DOCTYPE html>`);
|
||||
globalThis.DOMParser = window.DOMParser;
|
||||
globalThis.XMLSerializer = window.XMLSerializer;
|
||||
const xmlDocument = Blockly.utils.xml.textToDomDocument(
|
||||
`<xml xmlns="${Blockly.utils.xml.NAME_SPACE}"></xml>`);
|
||||
Blockly.utils.xml.setDocument(xmlDocument);
|
||||
Blockly.utils.xml.injectDependencies(window);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user