From 90ad0789f6beab2d168baa1934a460d5320a155d Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Tue, 22 Oct 2019 14:26:59 -0400 Subject: [PATCH] Fix 11 warnings related to variables and variable_model. (#3278) * Fix 10 warnings related to variables and variable_model. --- core/block.js | 8 ++++++++ core/variable_map.js | 14 +++++++------- core/variables.js | 10 ++++++---- core/variables_dynamic.js | 6 +++--- core/workspace.js | 6 +++--- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/core/block.js b/core/block.js index 9a439349d..25510b8bf 100644 --- a/core/block.js +++ b/core/block.js @@ -300,6 +300,14 @@ Blockly.Block.prototype.domToMutation; */ Blockly.Block.prototype.suppressPrefixSuffix; +/** + * An optional property for declaring developer variables. Return a list of + * variable names for use by generators. Developer variables are never shown to + * the user, but are declared as global variables in the generated code. + * @type {?function():!Array.} + */ +Blockly.Block.prototype.getDeveloperVariables; + /** * Dispose of this block. * @param {boolean} healStack If true, then try to heal any gap by connecting diff --git a/core/variable_map.js b/core/variable_map.js index 76fefb438..f52aba2e2 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -168,7 +168,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, * their type. This will default to '' which is a specific type. * @param {?string=} opt_id The unique ID of the variable. This will default to * a UUID. - * @return {Blockly.VariableModel} The newly created variable. + * @return {!Blockly.VariableModel} The newly created variable. */ Blockly.VariableMap.prototype.createVariable = function(name, opt_type, opt_id) { @@ -248,13 +248,13 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) { replace('%2', variableName); Blockly.confirm(confirmText, function(ok) { - if (ok) { - map.deleteVariableInternal_(variable, uses); + if (ok && variable) { + map.deleteVariableInternal(variable, uses); } }); } else { // No confirmation necessary for a single block. - map.deleteVariableInternal_(variable, uses); + map.deleteVariableInternal(variable, uses); } } else { console.warn("Can't delete non-existent variable: " + id); @@ -266,9 +266,9 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) { * user for confirmation. * @param {!Blockly.VariableModel} variable Variable to delete. * @param {!Array.} uses An array of uses of the variable. - * @private + * @package */ -Blockly.VariableMap.prototype.deleteVariableInternal_ = function(variable, +Blockly.VariableMap.prototype.deleteVariableInternal = function(variable, uses) { var existingGroup = Blockly.Events.getGroup(); if (!existingGroup) { @@ -292,7 +292,7 @@ Blockly.VariableMap.prototype.deleteVariableInternal_ = function(variable, * Find the variable by the given name and type and return it. Return null if * it is not found. * @param {string} name The name to check for. - * @param {string=} opt_type The type of the variable. If not provided it + * @param {?string=} opt_type The type of the variable. If not provided it * defaults to the empty string, which is a specific type. * @return {Blockly.VariableModel} The variable with the given name, or null if * it was not found. diff --git a/core/variables.js b/core/variables.js index ab85adb6e..f15d92aff 100644 --- a/core/variables.js +++ b/core/variables.js @@ -500,10 +500,11 @@ Blockly.Variables.getOrCreateVariablePackage = function(workspace, id, opt_name, */ Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) { var potentialVariableMap = workspace.getPotentialVariableMap(); + var variable = null; // Try to just get the variable, by ID if possible. if (id) { // Look in the real variable map before checking the potential variable map. - var variable = workspace.getVariableById(id); + variable = workspace.getVariableById(id); if (!variable && potentialVariableMap) { variable = potentialVariableMap.getVariableById(id); } @@ -518,7 +519,7 @@ Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) { throw Error('Tried to look up a variable by name without a type'); } // Otherwise look up by name and type. - var variable = workspace.getVariable(opt_name, opt_type); + variable = workspace.getVariable(opt_name, opt_type); if (!variable && potentialVariableMap) { variable = potentialVariableMap.getVariable(opt_name, opt_type); } @@ -547,10 +548,11 @@ Blockly.Variables.createVariable_ = function(workspace, id, opt_name, } // Create a potential variable if in the flyout. + var variable = null; if (potentialVariableMap) { - var variable = potentialVariableMap.createVariable(opt_name, opt_type, id); + variable = potentialVariableMap.createVariable(opt_name, opt_type, id); } else { // In the main workspace, create a real variable. - var variable = workspace.createVariable(opt_name, opt_type, id); + variable = workspace.createVariable(opt_name, opt_type, id); } return variable; }; diff --git a/core/variables_dynamic.js b/core/variables_dynamic.js index e07f03eae..0d8d1548a 100644 --- a/core/variables_dynamic.js +++ b/core/variables_dynamic.js @@ -33,15 +33,15 @@ goog.require('Blockly.VariableModel'); Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) { Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), - null, 'String'); + undefined, 'String'); }; Blockly.VariablesDynamic.onCreateVariableButtonClick_Number = function(button) { Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), - null, 'Number'); + undefined, 'Number'); }; Blockly.VariablesDynamic.onCreateVariableButtonClick_Colour = function(button) { Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), - null, 'Colour'); + undefined, 'Colour'); }; /** * Construct the elements (blocks and button) required by the flyout for the diff --git a/core/workspace.js b/core/workspace.js index abb4ab85d..10d5b11ab 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -516,7 +516,7 @@ Blockly.Workspace.prototype.renameVariableById = function(id, newName) { * their type. This will default to '' which is a specific type. * @param {?string=} opt_id The unique ID of the variable. This will default to * a UUID. - * @return {Blockly.VariableModel} The newly created variable. + * @return {!Blockly.VariableModel} The newly created variable. */ Blockly.Workspace.prototype.createVariable = function(name, opt_type, opt_id) { return this.variableMap_.createVariable(name, opt_type, opt_id); @@ -548,7 +548,7 @@ Blockly.Workspace.prototype.deleteVariableById = function(id) { * @private */ Blockly.Workspace.prototype.deleteVariableInternal_ = function(variable, uses) { - this.variableMap_.deleteVariableInternal_(variable, uses); + this.variableMap_.deleteVariableInternal(variable, uses); }; /** @@ -593,7 +593,7 @@ Blockly.Workspace.prototype.getVariableById = function(id) { * Find the variable with the specified type. If type is null, return list of * variables with empty string type. * @param {?string} type Type of the variables to find. - * @return {Array.} The sought after variables of the + * @return {!Array.} The sought after variables of the * passed in type. An empty array if none are found. */ Blockly.Workspace.prototype.getVariablesOfType = function(type) {