diff --git a/core/utils/xml.js b/core/utils/xml.js index 26f7bfc47..d7e8d77cd 100644 --- a/core/utils/xml.js +++ b/core/utils/xml.js @@ -16,65 +16,71 @@ * @name Blockly.utils.xml * @namespace */ -goog.provide('Blockly.utils.xml'); +goog.module('Blockly.utils.xml'); +goog.module.declareLegacyNamespace(); /** * Namespace for Blockly's XML. */ -Blockly.utils.xml.NAME_SPACE = 'https://developers.google.com/blockly/xml'; +const NAME_SPACE = 'https://developers.google.com/blockly/xml'; +exports.NAME_SPACE = NAME_SPACE; /** * Get the document object. This method is overridden in the Node.js build of * Blockly. See gulpfile.js, package-blockly-node task. + * + * Note that this function is named getDocument so as to not shadow the + * global of the same name, but (for now) exported as .document to not + * break existing importers. + * * @return {!Document} The document object. - * @public */ -Blockly.utils.xml.document = function() { +const getDocument = function() { return document; }; +exports.document = getDocument; /** * Create DOM element for XML. * @param {string} tagName Name of DOM element. * @return {!Element} New DOM element. - * @public */ -Blockly.utils.xml.createElement = function(tagName) { - return Blockly.utils.xml.document().createElementNS( - Blockly.utils.xml.NAME_SPACE, tagName); +const createElement = function(tagName) { + return exports.document().createElementNS(NAME_SPACE, tagName); }; +exports.createElement = createElement; /** * Create text element for XML. * @param {string} text Text content. * @return {!Text} New DOM text node. - * @public */ -Blockly.utils.xml.createTextNode = function(text) { - return Blockly.utils.xml.document().createTextNode(text); +const createTextNode = function(text) { + return exports.document().createTextNode(text); }; +exports.createTextNode = createTextNode; /** * Converts an XML string into a DOM tree. * @param {string} text XML string. * @return {Document} The DOM document. * @throws if XML doesn't parse. - * @public */ -Blockly.utils.xml.textToDomDocument = function(text) { - var oParser = new DOMParser(); +const textToDomDocument = function(text) { + const oParser = new DOMParser(); return oParser.parseFromString(text, 'text/xml'); }; +exports.textToDomDocument = textToDomDocument; /** * Converts a DOM structure into plain text. * Currently the text format is fairly ugly: all one line with no whitespace. * @param {!Node} dom A tree of XML nodes. * @return {string} Text representation. - * @public */ -Blockly.utils.xml.domToText = function(dom) { - var oSerializer = new XMLSerializer(); +const domToText = function(dom) { + const oSerializer = new XMLSerializer(); return oSerializer.serializeToString(dom); }; +exports.domToText = domToText; diff --git a/tests/deps.js b/tests/deps.js index 8dd1373ea..33025e20b 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -229,7 +229,7 @@ goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], [], {'lang' goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); +goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.Names', 'Blockly.VariableModel', 'Blockly.utils.idGenerator', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils.idGenerator'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});