From 2ad4333d12577a98e05905343ee55dfb83784bcb Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Nov 2018 13:02:33 -0800 Subject: [PATCH] Look up variable by name if not found by ID --- core/variables.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/variables.js b/core/variables.js index fbd627f48..36cb36358 100644 --- a/core/variables.js +++ b/core/variables.js @@ -539,7 +539,13 @@ Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) { if (!variable && potentialVariableMap) { variable = potentialVariableMap.getVariableById(id); } - } else if (opt_name) { + if (variable) { + return variable; + } + } + // If there was no ID, or there was an ID but it didn't match any variables, + // look up by name and type. + if (opt_name) { if (opt_type == undefined) { throw Error('Tried to look up a variable by name without a type'); }