From 1140a6ccf21411292f7184bddae5af13e78ea9ed Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 5 Oct 2015 16:08:44 -0700 Subject: [PATCH] Simplify XML parser. --- core/xml.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/xml.js b/core/xml.js index d00decfa0..d7cc991b5 100644 --- a/core/xml.js +++ b/core/xml.js @@ -330,12 +330,14 @@ Blockly.Xml.domToBlockHeadless_ = } var input; - // Find the first 'real' grandchild node (that isn't whitespace). - var firstRealGrandchild = null; + // Find any enclosed blocks. + var childBlockNode = null; for (var j = 0, grandchildNode; grandchildNode = xmlChild.childNodes[j]; j++) { - if (grandchildNode.nodeType != 3 || !grandchildNode.data.match(/^\s*$/)) { - firstRealGrandchild = grandchildNode; + if (grandchildNode.nodeType == 1) { + if (grandchildNode.nodeName.toLowerCase() == 'block') { + childBlockNode = grandchildNode; + } } } @@ -395,10 +397,9 @@ Blockly.Xml.domToBlockHeadless_ = prototypeName); break; } - if (firstRealGrandchild && - firstRealGrandchild.nodeName.toLowerCase() == 'block') { + if (childBlockNode) { blockChild = Blockly.Xml.domToBlockHeadless_(workspace, - firstRealGrandchild, opt_reuseBlock); + childBlockNode, opt_reuseBlock); if (blockChild.outputConnection) { input.connection.connect(blockChild.outputConnection); } else if (blockChild.previousConnection) { @@ -409,8 +410,7 @@ Blockly.Xml.domToBlockHeadless_ = } break; case 'next': - if (firstRealGrandchild && - firstRealGrandchild.nodeName.toLowerCase() == 'block') { + if (childBlockNode) { if (!block.nextConnection) { throw 'Next statement does not exist.'; } else if (block.nextConnection.targetConnection) { @@ -418,7 +418,7 @@ Blockly.Xml.domToBlockHeadless_ = throw 'Next statement is already connected.'; } blockChild = Blockly.Xml.domToBlockHeadless_(workspace, - firstRealGrandchild, opt_reuseBlock); + childBlockNode, opt_reuseBlock); if (!blockChild.previousConnection) { throw 'Next block does not have previous statement.'; }