refactor: Remove last remaining circular import in core/ (#6818)

* refactor(xml): Move textToDom to core/utils/xml.ts

  This function being in core/xml.ts was the cause for the last
  remaining circular import in core/ (between variables.ts and
  xml.ts).

  Moving it to utils/xml.ts makes sense anyway, since there is
  nothing Blockly-specific about this function.

  Fixes #6817.

* fix(closure): Reenable goog.declareModuleId multiple-call check

  Reenable an assertion which check to make sure that
  goog.declareModuleId is not called more than once in a module
  (and which also catches circular imports amongst ES modules, which
  are not detected by closure-make-deps).

* chore(tests,demos): Augo-migrate use of textToDom

  Testing the migration file entry by auto-migrating all uses of
  Blockly.Xml.textToDom to Blockly.utils.xml.textToDom.

* chore(blocks): Manually migrate remaining use of textToDom

  Update the one remaining call to textToDom (in blocks/lists.ts)
  to the function's new location - also removing the last use of
  the Blockly.Xml / core/xml.ts) module from this file.

* docs(xml): Remove unneeded @alias per comments on PR #6818

* fix(imports): Remove unused import
This commit is contained in:
Christopher Allen
2023-02-07 12:11:11 +00:00
committed by GitHub
parent d808c068d2
commit 167e26521c
48 changed files with 292 additions and 261 deletions

View File

@@ -138,7 +138,7 @@ AppController.prototype.formatBlockLibraryForExport_ = function(blockXmlMap) {
// Append each block node to XML DOM.
for (var blockType in blockXmlMap) {
var blockXmlDom = Blockly.Xml.textToDom(blockXmlMap[blockType]);
var blockXmlDom = Blockly.utils.xml.textToDom(blockXmlMap[blockType]);
var blockNode = blockXmlDom.firstElementChild;
xmlDom.appendChild(blockNode);
}
@@ -155,7 +155,7 @@ AppController.prototype.formatBlockLibraryForExport_ = function(blockXmlMap) {
* @private
*/
AppController.prototype.formatBlockLibraryForImport_ = function(xmlText) {
var inputXml = Blockly.Xml.textToDom(xmlText);
var inputXml = Blockly.utils.xml.textToDom(xmlText);
// Convert the live HTMLCollection of child Elements into a static array,
// since the addition to editorWorkspaceXml below removes it from inputXml.
var inputChildren = Array.from(inputXml.children);
@@ -192,7 +192,7 @@ AppController.prototype.formatBlockLibraryForImport_ = function(xmlText) {
* @private
*/
AppController.prototype.getBlockTypeFromXml_ = function(xmlText) {
var xmlDom = Blockly.Xml.textToDom(xmlText);
var xmlDom = Blockly.utils.xml.textToDom(xmlText);
// Find factory base block.
var factoryBaseBlockXml = xmlDom.getElementsByTagName('block')[0];
// Get field elements from factory base.

View File

@@ -89,7 +89,7 @@ BlockLibraryStorage.prototype.removeBlock = function(blockType) {
BlockLibraryStorage.prototype.getBlockXml = function(blockType) {
var xml = this.blocks[blockType] || null;
if (xml) {
var xml = Blockly.Xml.textToDom(xml);
var xml = Blockly.utils.xml.textToDom(xml);
}
return xml;
};

View File

@@ -304,7 +304,7 @@ BlockFactory.disableEnableLink = function() {
*/
BlockFactory.showStarterBlock = function() {
BlockFactory.mainWorkspace.clear();
var xml = Blockly.Xml.textToDom(BlockFactory.STARTER_BLOCK_XML_TEXT);
var xml = Blockly.utils.xml.textToDom(BlockFactory.STARTER_BLOCK_XML_TEXT);
Blockly.Xml.domToWorkspace(xml, BlockFactory.mainWorkspace);
};

View File

@@ -26,7 +26,7 @@ StandardCategories.categoryMap = Object.create(null);
StandardCategories.categoryMap['logic'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Logic');
StandardCategories.categoryMap['logic'].xml =
Blockly.Xml.textToDom(
Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="controls_if"></block>' +
'<block type="logic_compare"></block>' +
@@ -41,7 +41,7 @@ StandardCategories.categoryMap['logic'].hue = 210;
StandardCategories.categoryMap['loops'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Loops');
StandardCategories.categoryMap['loops'].xml =
Blockly.Xml.textToDom(
Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="controls_repeat_ext">' +
'<value name="TIMES">' +
@@ -76,7 +76,7 @@ StandardCategories.categoryMap['loops'].hue = 120;
StandardCategories.categoryMap['math'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Math');
StandardCategories.categoryMap['math'].xml =
Blockly.Xml.textToDom(
Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="math_number"></block>' +
'<block type="math_arithmetic">' +
@@ -169,7 +169,7 @@ StandardCategories.categoryMap['math'].hue = 230;
StandardCategories.categoryMap['text'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Text');
StandardCategories.categoryMap['text'].xml =
Blockly.Xml.textToDom(
Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="text"></block>' +
'<block type="text_join"></block>' +
@@ -252,7 +252,7 @@ StandardCategories.categoryMap['text'].hue = 160;
StandardCategories.categoryMap['lists'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Lists');
StandardCategories.categoryMap['lists'].xml =
Blockly.Xml.textToDom(
Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="lists_create_with">' +
'<mutation items="0"></mutation>' +
@@ -309,7 +309,7 @@ StandardCategories.categoryMap['lists'].hue = 260;
StandardCategories.categoryMap['colour'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Colour');
StandardCategories.categoryMap['colour'].xml =
Blockly.Xml.textToDom(
Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="colour_picker"></block>' +
'<block type="colour_random"></block>' +

View File

@@ -701,7 +701,7 @@ WorkspaceFactoryController.prototype.importFile = function(file, importMode) {
// Try to parse XML from file and load it into toolbox editing area.
// Print error message if fail.
try {
var tree = Blockly.Xml.textToDom(reader.result);
var tree = Blockly.utils.xml.textToDom(reader.result);
if (importMode === WorkspaceFactoryController.MODE_TOOLBOX) {
// Switch mode.
controller.setMode(WorkspaceFactoryController.MODE_TOOLBOX);

View File

@@ -799,7 +799,7 @@ function init() {
mainWorkspace);
} else {
var xml = '<xml xmlns="https://developers.google.com/blockly/xml"><block type="factory_base" deletable="false" movable="false"></block></xml>';
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), mainWorkspace);
Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(xml), mainWorkspace);
}
mainWorkspace.clearUndo();

View File

@@ -127,11 +127,11 @@ Code.loadBlocks = function(defaultXml) {
} else if (loadOnce) {
// Language switching stores the blocks during the reload.
delete window.sessionStorage.loadOnceBlocks;
var xml = Blockly.Xml.textToDom(loadOnce);
var xml = Blockly.utils.xml.textToDom(loadOnce);
Blockly.Xml.domToWorkspace(xml, Code.workspace);
} else if (defaultXml) {
// Load the editor with default starting blocks.
var xml = Blockly.Xml.textToDom(defaultXml);
var xml = Blockly.utils.xml.textToDom(defaultXml);
Blockly.Xml.domToWorkspace(xml, Code.workspace);
} else if ('BlocklyStorage' in window) {
// Restore saved blocks in a separate thread so that subsequent
@@ -264,7 +264,7 @@ Code.tabClick = function(clickedName) {
var xmlText = xmlTextarea.value;
var xmlDom = null;
try {
xmlDom = Blockly.Xml.textToDom(xmlText);
xmlDom = Blockly.utils.xml.textToDom(xmlText);
} catch (e) {
var q = window.confirm(
MSG['parseError'].replace(/%1/g, 'XML').replace('%2', e));
@@ -459,7 +459,7 @@ Code.init = function() {
var toolboxText = document.getElementById('toolbox').outerHTML;
toolboxText = toolboxText.replace(/(^|[^%]){(\w+)}/g,
function(m, p1, p2) {return p1 + MSG[p2];});
var toolboxXml = Blockly.Xml.textToDom(toolboxText);
var toolboxXml = Blockly.utils.xml.textToDom(toolboxText);
Code.workspace = Blockly.inject('content_blocks',
{grid: