Look up variable by name if not found by ID

This commit is contained in:
Rachel Fenichel
2018-11-27 13:02:33 -08:00
parent c03ea23000
commit 2ad4333d12

View File

@@ -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');
}