mirror of
https://github.com/google/blockly.git
synced 2026-01-10 10:27:08 +01:00
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
35 lines
1018 B
JavaScript
35 lines
1018 B
JavaScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Blockly core module for Node. It includes blockly-node.js
|
|
* and adds a helper method for setting the locale.
|
|
*/
|
|
|
|
/* eslint-disable */
|
|
'use strict';
|
|
|
|
// Add a helper method to set the Blockly locale.
|
|
Blockly.setLocale = function (locale) {
|
|
Blockly.Msg = Blockly.Msg || {};
|
|
Object.keys(locale).forEach(function (k) {
|
|
Blockly.Msg[k] = locale[k];
|
|
});
|
|
};
|
|
|
|
// Override textToDomDocument and provide Node.js alternatives to DOMParser and
|
|
// 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;
|
|
};
|
|
}
|