From f7f664063b4358fd9df985fc66f6fd8679a54efa Mon Sep 17 00:00:00 2001 From: marisaleung Date: Wed, 24 May 2017 10:51:54 -0700 Subject: [PATCH] Deserialization variables at top. --- core/xml.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/xml.js b/core/xml.js index 4e9e4b989..bd42c1eae 100644 --- a/core/xml.js +++ b/core/xml.js @@ -332,6 +332,7 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) { if (workspace.setResizesEnabled) { workspace.setResizesEnabled(false); } + var variablesFirst = true; for (var i = 0; i < childCount; i++) { var xmlChild = xml.childNodes[i]; var name = xmlChild.nodeName.toLowerCase(); @@ -347,16 +348,20 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) { if (!isNaN(blockX) && !isNaN(blockY)) { block.moveBy(workspace.RTL ? width - blockX : blockX, blockY); } + variablesFirst = false; } else if (name == 'shadow') { goog.asserts.fail('Shadow block cannot be a top-level block.'); + variablesFirst = false; } else if (name == 'variables') { - if (i == 1) { + if (variablesFirst) { Blockly.Xml.domToVariables(xmlChild, workspace); } else { - throw Error('\'variables\' tag must be the first element in the' + - 'workspace XML, but it was found in another location.'); + throw Error('\'variables\' tag must exist once before block and ' + + 'shadow tag elements in the workspace XML, but it was found in ' + + 'another location.'); } + variablesFirst = false; } } if (!existingGroup) {