From 4262b090028e680aee094ec0087bcf8acaf9fab8 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 23 Oct 2017 17:28:01 -0700 Subject: [PATCH] Resolve 106 warnings. --- blocks/text.js | 2 ++ core/block.js | 8 ++--- core/block_drag_surface.js | 2 +- core/block_svg.js | 8 ++--- core/blockly.js | 10 +++--- core/blocks.js | 2 +- core/events.js | 18 +++++----- core/extensions.js | 4 +-- core/field.js | 2 +- core/field_number.js | 1 + core/field_variable.js | 8 ++--- core/flyout_horizontal.js | 2 +- core/flyout_vertical.js | 2 +- core/grid.js | 2 +- core/input.js | 2 +- core/msg.js | 2 +- core/scrollbar.js | 5 +-- core/toolbox.js | 10 +++--- core/touch.js | 7 ++-- core/ui_menu_utils.js | 1 + core/utils.js | 12 +++---- core/variable_map.js | 40 +++++++++++----------- core/variable_model.js | 8 ++--- core/variables.js | 2 +- core/workspace.js | 31 ++++++++--------- core/workspace_audio.js | 4 ++- core/workspace_svg.js | 26 +++++++-------- core/xml.js | 68 +++++++++++++++++++------------------- tests/jsunit/input_test.js | 10 +++--- 29 files changed, 154 insertions(+), 145 deletions(-) diff --git a/blocks/text.js b/blocks/text.js index 3e0d62de9..208972e14 100644 --- a/blocks/text.js +++ b/blocks/text.js @@ -587,6 +587,7 @@ Blockly.Constants.Text.QUOTE_IMAGE_MIXIN = { /** * Inserts appropriate quote images before and after the named field. * @param {string} fieldName The name of the field to wrap with quotes. + * @this Blockly.Block */ quoteField_: function(fieldName) { for (var i = 0, input; input = this.inputList[i]; i++) { @@ -607,6 +608,7 @@ Blockly.Constants.Text.QUOTE_IMAGE_MIXIN = { * @param {boolean} open If the image should be open quote (“ in LTR). * Otherwise, a closing quote is used (” in LTR). * @returns {!Blockly.FieldImage} The new field. + * @this Blockly.Block */ newQuote_: function(open) { var isLeft = this.RTL? !open : open; diff --git a/core/block.js b/core/block.js index 86a94b414..15b4a68df 100644 --- a/core/block.js +++ b/core/block.js @@ -48,7 +48,7 @@ goog.require('goog.string'); * @param {?string} prototypeName Name of the language object containing * type-specific functions for this block. * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise - * create a new id. + * create a new ID. * @constructor */ Blockly.Block = function(workspace, prototypeName, opt_id) { @@ -261,7 +261,7 @@ Blockly.Block.prototype.dispose = function(healStack) { /** * Unplug this block from its superior block. If this block is a statement, * optionally reconnect the block underneath with the block on top. - * @param {boolean} opt_healStack Disconnect child statement and reconnect + * @param {boolean=} opt_healStack Disconnect child statement and reconnect * stack. Defaults to false. */ Blockly.Block.prototype.unplug = function(opt_healStack) { @@ -619,9 +619,9 @@ Blockly.Block.prototype.setColour = function(colour) { if (!isNaN(hue) && 0 <= hue && hue <= 360) { this.hue_ = hue; this.colour_ = Blockly.hueToRgb(hue); - } else if (goog.isString(colour) && colour.match(/^#[0-9a-fA-F]{6}$/)) { + } else if (goog.isString(colour) && /^#[0-9a-fA-F]{6}$/.test(colour)) { this.colour_ = colour; - // Only store hue if colour is set as a hue + // Only store hue if colour is set as a hue. this.hue_ = null; } else { throw 'Invalid colour: ' + colour; diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index be72fa8e8..5a3948419 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -202,7 +202,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { * element. * If the block is being deleted it doesn't need to go back to the original * surface, since it would be removed immediately during dispose. - * @param {Element} opt_newSurface Surface the dragging blocks should be moved + * @param {Element=} opt_newSurface Surface the dragging blocks should be moved * to, or null if the blocks should be removed from this surface without * being moved to a different surface. */ diff --git a/core/block_svg.js b/core/block_svg.js index cb5834fb9..56671d1a2 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -47,7 +47,7 @@ goog.require('goog.userAgent'); * @param {?string} prototypeName Name of the language object containing * type-specific functions for this block. * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise - * create a new id. + * create a new ID. * @extends {Blockly.Block} * @constructor */ @@ -121,7 +121,7 @@ Blockly.BlockSvg.prototype.dragStartXY_ = null; /** * Map from IDs for warnings text to PIDs of functions to apply them. * Used to be able to maintain multiple warnings. - * @type {Object} + * @type {Object.} * @private */ Blockly.BlockSvg.prototype.warningTextDb_ = null; @@ -534,7 +534,7 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) { /** * Create an ordered list of all text fields and connected inputs. - * @return {!Array} The ordered list. + * @return {!Array.} The ordered list. * @private */ Blockly.BlockSvg.prototype.createTabList_ = function() { @@ -1160,7 +1160,7 @@ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) { } this.warning.setText(/** @type {string} */ (text), id); } else { - // Dispose all warnings if no id is given. + // Dispose all warnings if no ID is given. if (this.warning && !id) { this.warning.dispose(); changedState = true; diff --git a/core/blockly.js b/core/blockly.js index 1e832ac16..601e98527 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -395,14 +395,14 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) { * Bind an event to a function call. When calling the function, verifies that * it belongs to the touch stream that is currently being processed, and splits * multitouch events into multiple events as needed. - * @param {!Node} node Node upon which to listen. + * @param {!EventTarget} node Node upon which to listen. * @param {string} name Event name to listen to (e.g. 'mousedown'). * @param {Object} thisObject The value of 'this' in the function. * @param {!Function} func Function to call when event is triggered. - * @param {boolean} opt_noCaptureIdentifier True if triggering on this event + * @param {boolean=} opt_noCaptureIdentifier True if triggering on this event * should not block execution of other event handlers on this touch or other * simultaneous touches. - * @param {boolean} opt_noPreventDefault True if triggering on this event + * @param {boolean=} opt_noPreventDefault True if triggering on this event * should prevent the default handler. False by default. If * opt_noPreventDefault is provided, opt_noCaptureIdentifier must also be * provided. @@ -461,7 +461,7 @@ Blockly.bindEventWithChecks_ = function(node, name, thisObject, func, * simultaneous event processing. * @deprecated in favor of bindEventWithChecks_, but preserved for external * users. - * @param {!Node} node Node upon which to listen. + * @param {!EventTarget} node Node upon which to listen. * @param {string} name Event name to listen to (e.g. 'mousedown'). * @param {Object} thisObject The value of 'this' in the function. * @param {!Function} func Function to call when event is triggered. @@ -528,7 +528,7 @@ Blockly.unbindEvent_ = function(bindData) { * @return {boolean} True if number, false otherwise. */ Blockly.isNumber = function(str) { - return !!str.match(/^\s*-?\d+(\.\d+)?\s*$/); + return /^\s*-?\d+(\.\d+)?\s*$/.test(str); }; // IE9 does not have a console. Create a stub to stop errors. diff --git a/core/blocks.js b/core/blocks.js index 5b78050aa..c27be1d40 100644 --- a/core/blocks.js +++ b/core/blocks.js @@ -32,6 +32,6 @@ goog.provide('Blockly.Blocks'); /* * A mapping of block type names to block prototype objects. - * @type {!Object} + * @type {!Object.} */ Blockly.Blocks = new Object(null); diff --git a/core/events.js b/core/events.js index a4f0706a7..c2762b8bf 100644 --- a/core/events.js +++ b/core/events.js @@ -482,7 +482,7 @@ Blockly.Events.Create.prototype.run = function(forward) { block.dispose(false, false); } else if (id == this.blockId) { // Only complain about root-level block. - console.warn("Can't uncreate non-existant block: " + id); + console.warn("Can't uncreate non-existent block: " + id); } } } @@ -558,7 +558,7 @@ Blockly.Events.Delete.prototype.run = function(forward) { block.dispose(false, false); } else if (id == this.blockId) { // Only complain about root-level block. - console.warn("Can't delete non-existant block: " + id); + console.warn("Can't delete non-existent block: " + id); } } } else { @@ -649,7 +649,7 @@ Blockly.Events.Change.prototype.run = function(forward) { var workspace = this.getEventWorkspace_(); var block = workspace.getBlockById(this.blockId); if (!block) { - console.warn("Can't change non-existant block: " + this.blockId); + console.warn("Can't change non-existent block: " + this.blockId); return; } if (block.mutator) { @@ -666,7 +666,7 @@ Blockly.Events.Change.prototype.run = function(forward) { field.callValidator(value); field.setValue(value); } else { - console.warn("Can't set non-existant field: " + this.name); + console.warn("Can't set non-existent field: " + this.name); } break; case 'comment': @@ -818,7 +818,7 @@ Blockly.Events.Move.prototype.run = function(forward) { var workspace = this.getEventWorkspace_(); var block = workspace.getBlockById(this.blockId); if (!block) { - console.warn("Can't move non-existant block: " + this.blockId); + console.warn("Can't move non-existent block: " + this.blockId); return; } var parentId = forward ? this.newParentId : this.oldParentId; @@ -828,7 +828,7 @@ Blockly.Events.Move.prototype.run = function(forward) { if (parentId) { parentBlock = workspace.getBlockById(parentId); if (!parentBlock) { - console.warn("Can't connect to non-existant block: " + parentId); + console.warn("Can't connect to non-existent block: " + parentId); return; } } @@ -852,7 +852,7 @@ Blockly.Events.Move.prototype.run = function(forward) { if (parentConnection) { blockConnection.connect(parentConnection); } else { - console.warn("Can't connect to non-existant input: " + inputName); + console.warn("Can't connect to non-existent input: " + inputName); } } }; @@ -861,8 +861,8 @@ Blockly.Events.Move.prototype.run = function(forward) { * Class for a UI event. * @param {Blockly.Block} block The affected block. * @param {string} element One of 'selected', 'comment', 'mutator', etc. - * @param {string} oldValue Previous value of element. - * @param {string} newValue New value of element. + * @param {*} oldValue Previous value of element. + * @param {*} newValue New value of element. * @extends {Blockly.Events.Abstract} * @constructor */ diff --git a/core/extensions.js b/core/extensions.js index 28999e981..cba4d63c0 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -309,7 +309,7 @@ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { * reported as warnings in the console, and are never fatal. * @param {string} dropdownName The name of the field whose value is the key * to the lookup table. - * @param {!Object} lookupTable The table of field values to + * @param {!Object.} lookupTable The table of field values to * tooltip text. * @return {Function} The extension function. */ @@ -369,7 +369,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, * Emits console warnings when they are not. * @param {!Blockly.Block} block The block containing the dropdown * @param {string} dropdownName The name of the dropdown - * @param {!Object} lookupTable The string lookup table + * @param {!Object.} lookupTable The string lookup table * @private */ Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName, diff --git a/core/field.js b/core/field.js index 13bdbd74f..1a17519c9 100644 --- a/core/field.js +++ b/core/field.js @@ -146,7 +146,7 @@ Blockly.Field.prototype.init = function() { 'ry': 4, 'x': -Blockly.BlockSvg.SEP_SPACE_X / 2, 'y': 0, - 'height': 16}, this.fieldGroup_, this.sourceBlock_.workspace); + 'height': 16}, this.fieldGroup_); /** @type {!Element} */ this.textElement_ = Blockly.utils.createSvgElement('text', {'class': 'blocklyText', 'y': this.size_.height - 12.5}, diff --git a/core/field_number.js b/core/field_number.js index 722b0eefa..d3575fde3 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -29,6 +29,7 @@ goog.provide('Blockly.FieldNumber'); goog.require('Blockly.FieldTextInput'); goog.require('goog.math'); + /** * Class for an editable number field. * @param {(string|number)=} opt_value The initial content of the field. The value diff --git a/core/field_variable.js b/core/field_variable.js index 3e06c96ff..dd2220fcf 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -41,8 +41,8 @@ goog.require('goog.string'); * a unique variable name will be generated. * @param {Function=} opt_validator A function that is executed when a new * option is selected. Its sole argument is the new option value. - * @param {Array.} opt_variableTypes A list of the types of variables to - * include in the dropdown. + * @param {Array.=} opt_variableTypes A list of the types of variables + * to include in the dropdown. * @extends {Blockly.FieldDropdown} * @constructor */ @@ -118,7 +118,7 @@ Blockly.FieldVariable.prototype.setValue = function(value) { newText = variable.name; } // TODO(marisaleung): Remove name lookup after converting all Field Variable - // instances to use id instead of name. + // instances to use ID instead of name. else if (variable = this.sourceBlock_.workspace.getVariable(value)) { newValue = variable.getId(); } @@ -217,7 +217,7 @@ Blockly.FieldVariable.dropdownCreate = function() { */ Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) { var id = menuItem.getValue(); - // TODO(marisaleung): change setValue() to take in an id as the parameter. + // TODO(marisaleung): change setValue() to take in an ID as the parameter. // Then remove itemText. var itemText; if (this.sourceBlock_ && this.sourceBlock_.workspace) { diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index e94c0be47..5a3888021 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -353,7 +353,7 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { /** * Compute height of flyout. Position button under each block. * For RTL: Lay out the blocks right-aligned. - * @param {!Array} blocks The blocks to reflow. + * @param {!Array.} blocks The blocks to reflow. * @private */ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function(blocks) { diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index d6ad60726..838befcab 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -328,7 +328,7 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { /** * Compute width of flyout. Position button under each block. * For RTL: Lay out the blocks right-aligned. - * @param {!Array} blocks The blocks to reflow. + * @param {!Array.} blocks The blocks to reflow. * @private */ Blockly.VerticalFlyout.prototype.reflowInternal_ = function(blocks) { diff --git a/core/grid.js b/core/grid.js index e87df6021..b0eeb3fc2 100644 --- a/core/grid.js +++ b/core/grid.js @@ -121,7 +121,7 @@ Blockly.Grid.prototype.getSpacing = function() { /** * Get the id of the pattern element, which should be randomized to avoid * conflicts with other Blockly instances on the page. - * @return {string} The pattern id. + * @return {string} The pattern ID. * @package */ Blockly.Grid.prototype.getPatternId = function() { diff --git a/core/input.js b/core/input.js index c2c006e52..5c7495dcf 100644 --- a/core/input.js +++ b/core/input.js @@ -101,7 +101,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { // Empty string, Null or undefined generates no field, unless field is named. if (!field && !opt_name) { - return this; + return index; } // Generate a FieldLabel when given a plain text field. if (goog.isString(field)) { diff --git a/core/msg.js b/core/msg.js index 4ebcad1ab..f6e520548 100644 --- a/core/msg.js +++ b/core/msg.js @@ -42,7 +42,7 @@ goog.getMsgOrig = goog.getMsg; * Overrides the default Closure function to check for a Blockly.Msg first. * Used infrequently, only known case is TODAY button in date picker. * @param {string} str Translatable string, places holders in the form {$foo}. - * @param {Object=} opt_values Maps place holder name to value. + * @param {Object.=} opt_values Maps place holder name to value. * @return {string} message with placeholders filled. * @suppress {duplicate} */ diff --git a/core/scrollbar.js b/core/scrollbar.js index d71b03d02..8498b2419 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -30,6 +30,7 @@ goog.provide('Blockly.ScrollbarPair'); goog.require('goog.dom'); goog.require('goog.events'); + /** * A note on units: most of the numbers that are in CSS pixels are scaled if the * scrollbar is in a mutator. @@ -189,7 +190,7 @@ Blockly.ScrollbarPair.prototype.getRatio_ = function(handlePosition, viewSize) { * @param {!Blockly.Workspace} workspace Workspace to bind the scrollbar to. * @param {boolean} horizontal True if horizontal, false if vertical. * @param {boolean=} opt_pair True if scrollbar is part of a horiz/vert pair. - * @param {string} opt_class A class to be applied to this scrollbar. + * @param {string=} opt_class A class to be applied to this scrollbar. * @constructor */ Blockly.Scrollbar = function(workspace, horizontal, opt_pair, opt_class) { @@ -591,7 +592,7 @@ Blockly.Scrollbar.prototype.resizeContentVertical = function(hostMetrics) { /** * Create all the DOM elements required for a scrollbar. * The resulting widget is not sized. - * @param {string} opt_class A class to be applied to this scrollbar. + * @param {string=} opt_class A class to be applied to this scrollbar. * @private */ Blockly.Scrollbar.prototype.createDom_ = function(opt_class) { diff --git a/core/toolbox.js b/core/toolbox.js index 40378e101..97decfc32 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -331,12 +331,12 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) { // Decode the colour for any potential message references // (eg. `%{BKY_MATH_HUE}`). var colour = Blockly.utils.replaceMessageReferences( - childIn.getAttribute('colour')); + childIn.getAttribute('colour')); if (goog.isString(colour)) { - if (colour.match(/^#[0-9a-fA-F]{6}$/)) { + if (/^#[0-9a-fA-F]{6}$/.test(colour)) { childOut.hexColour = colour; } else { - childOut.hexColour = Blockly.hueToRgb(colour); + childOut.hexColour = Blockly.hueToRgb(Number(colour)); } this.hasColours_ = true; } else { @@ -388,7 +388,7 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) { /** * Recursively add colours to this toolbox. - * @param {Blockly.Toolbox.TreeNode} opt_tree Starting point of tree. + * @param {Blockly.Toolbox.TreeNode=} opt_tree Starting point of tree. * Defaults to the root node. * @private */ @@ -695,6 +695,6 @@ Blockly.Toolbox.TreeNode.prototype.onKeyDown = function(e) { * @extends {Blockly.Toolbox.TreeNode} */ Blockly.Toolbox.TreeSeparator = function(config) { - Blockly.Toolbox.TreeNode.call(this, null, '', config); + Blockly.Toolbox.TreeNode.call(this, null, goog.html.SafeHtml.EMPTY, config); }; goog.inherits(Blockly.Toolbox.TreeSeparator, Blockly.Toolbox.TreeNode); diff --git a/core/touch.js b/core/touch.js index 37fde517b..4a494aa17 100644 --- a/core/touch.js +++ b/core/touch.js @@ -34,9 +34,10 @@ goog.require('goog.events'); goog.require('goog.events.BrowserFeature'); goog.require('goog.string'); + /** * Which touch events are we currently paying attention to? - * @type {DOMString} + * @type {?string} * @private */ Blockly.Touch.touchIdentifier_ = null; @@ -63,7 +64,7 @@ Blockly.longPid_ = 0; /** * Context menus on touch devices are activated using a long-press. - * Unfortunately the contextmenu touch event is currently (2015) only suported + * Unfortunately the contextmenu touch event is currently (2015) only supported * by Chrome. This function is fired on any touchstart event, queues a task, * which after about a second opens the context menu. The tasks is killed * if the touch event terminates early. @@ -154,7 +155,7 @@ Blockly.Touch.getTouchIdentifierFromEvent = function(e) { Blockly.Touch.checkTouchIdentifier = function(e) { var identifier = Blockly.Touch.getTouchIdentifierFromEvent(e); - // if (Blockly.touchIdentifier_ )is insufficient because android touch + // if (Blockly.touchIdentifier_ )is insufficient because Android touch // identifiers may be zero. if (Blockly.Touch.touchIdentifier_ != undefined && Blockly.Touch.touchIdentifier_ != null) { diff --git a/core/ui_menu_utils.js b/core/ui_menu_utils.js index 740873b33..8fda6021a 100644 --- a/core/ui_menu_utils.js +++ b/core/ui_menu_utils.js @@ -30,6 +30,7 @@ **/ goog.provide('Blockly.utils.uiMenu'); + /** * Get the size of a rendered goog.ui.Menu. * @param {!goog.ui.Menu} menu The menu to measure. diff --git a/core/utils.js b/core/utils.js index 6d1d0c482..8f2179e5c 100644 --- a/core/utils.js +++ b/core/utils.js @@ -45,7 +45,7 @@ goog.require('goog.userAgent'); * accessed through the exact name that was exported. Note, that all the exports * are happening as the last thing in the generated js files, so they won't be * accessible before JavaScript loads! - * @return {!Object} The message array. + * @return {!Object.} The message array. * @private */ Blockly.utils.getMessageArray_ = function() { @@ -285,11 +285,9 @@ Blockly.utils.getRelativeXY.XY_2D_REGEX_ = * @param {string} name Element's tag name. * @param {!Object} attrs Dictionary of attribute names and values. * @param {Element} parent Optional parent on which to append the element. - * @param {Blockly.Workspace=} opt_workspace Optional workspace for access to - * context (scale...). * @return {!SVGElement} Newly created SVG element. */ -Blockly.utils.createSvgElement = function(name, attrs, parent /*, opt_workspace */) { +Blockly.utils.createSvgElement = function(name, attrs, parent) { var e = /** @type {!SVGElement} */ ( document.createElementNS(Blockly.SVG_NS, name)); for (var key in attrs) { @@ -327,7 +325,7 @@ Blockly.utils.isRightButton = function(e) { * @param {!Event} e Mouse event. * @param {!Element} svg SVG element. * @param {SVGMatrix} matrix Inverted screen CTM to use. - * @return {!Object} Object with .x and .y properties. + * @return {!SVGPoint} Object with .x and .y properties. */ Blockly.utils.mouseToSvg = function(e, svg, matrix) { var svgPoint = svg.createSVGPoint(); @@ -453,7 +451,7 @@ Blockly.utils.replaceMessageReferences = function(message) { var interpolatedResult = Blockly.utils.tokenizeInterpolation_(message, false); // When parseInterpolationTokens == false, interpolatedResult should be at // most length 1. - return interpolatedResult.length ? interpolatedResult[0] : ""; + return interpolatedResult.length ? interpolatedResult[0] : ''; }; /** @@ -509,7 +507,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message, // 0 - Base case. // 1 - % found. // 2 - Digit found. - // 3 - Message ref found + // 3 - Message ref found. var state = 0; var buffer = []; var number = null; diff --git a/core/variable_map.js b/core/variable_map.js index b0c6e3819..04348494a 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -26,6 +26,7 @@ goog.provide('Blockly.VariableMap'); + /** * Class for a variable map. This contains a dictionary data structure with * variable types as keys and lists of variables as values. The list of @@ -38,7 +39,7 @@ goog.provide('Blockly.VariableMap'); * A map from variable type to list of variable names. The lists contain all * of the named variables in the workspace, including variables * that are not currently in use. - * @type {!Object>} + * @type {!Object.>} * @private */ this.variableMap_ = {}; @@ -59,7 +60,7 @@ Blockly.VariableMap.prototype.clear = function() { /** * Rename the given variable by updating its name in the variable map. - * @param {?Blockly.VariableModel} variable Variable to rename. + * @param {Blockly.VariableModel} variable Variable to rename. * @param {string} newName New variable name. */ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { @@ -103,17 +104,18 @@ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { }; /** - * Create a variable with a given name, optional type, and optional id. - * @param {!string} name The name of the variable. This must be unique across + * Create a variable with a given name, optional type, and optional ID. + * @param {string} name The name of the variable. This must be unique across * variables and procedures. - * @param {?string} opt_type The type of the variable like 'int' or 'string'. + * @param {string=} opt_type The type of the variable like 'int' or 'string'. * Does not need to be unique. Field_variable can filter variables based on * 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 + * @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) { +Blockly.VariableMap.prototype.createVariable = function(name, + opt_type, opt_id) { var variable = this.getVariable(name); if (variable) { if (opt_type && variable.type != opt_type) { @@ -122,11 +124,11 @@ Blockly.VariableMap.prototype.createVariable = function(name, opt_type, opt_id) 'type, "' + opt_type + '".'); } if (opt_id && variable.getId() != opt_id) { - throw Error('Variable "' + name + '" is already in use and its id is "' - + variable.getId() + '" which conflicts with the passed in ' + + throw Error('Variable "' + name + '" is already in use and its id is "' + + variable.getId() + '" which conflicts with the passed in ' + 'id, "' + opt_id + '".'); } - // The variable already exists and has the same id and type. + // The variable already exists and has the same ID and type. return variable; } if (opt_id && this.getVariableById(opt_id)) { @@ -148,7 +150,7 @@ Blockly.VariableMap.prototype.createVariable = function(name, opt_type, opt_id) /** * Delete a variable. - * @param {Blockly.VariableModel} variable Variable to delete. + * @param {!Blockly.VariableModel} variable Variable to delete. */ Blockly.VariableMap.prototype.deleteVariable = function(variable) { var variableList = this.variableMap_[variable.type]; @@ -164,8 +166,8 @@ Blockly.VariableMap.prototype.deleteVariable = function(variable) { /** * Find the variable by the given name and return it. Return null if it is not * found. - * @param {!string} name The name to check for. - * @return {?Blockly.VariableModel} The variable with the given name, or null if + * @param {string} name The name to check for. + * @return {Blockly.VariableModel} The variable with the given name, or null if * it was not found. */ Blockly.VariableMap.prototype.getVariable = function(name) { @@ -182,10 +184,10 @@ Blockly.VariableMap.prototype.getVariable = function(name) { }; /** - * Find the variable by the given id and return it. Return null if it is not + * Find the variable by the given ID and return it. Return null if it is not * found. - * @param {!string} id The id to check for. - * @return {?Blockly.VariableModel} The variable with the given id. + * @param {string} id The ID to check for. + * @return {Blockly.VariableModel} The variable with the given ID. */ Blockly.VariableMap.prototype.getVariableById = function(id) { var keys = Object.keys(this.variableMap_); @@ -204,7 +206,7 @@ Blockly.VariableMap.prototype.getVariableById = function(id) { * Get a list containing all of the variables of a 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.VariableMap.prototype.getVariablesOfType = function(type) { @@ -226,7 +228,7 @@ Blockly.VariableMap.prototype.getVariableTypes = function() { /** * Return all variables of all types. - * @return {!Array.} List of variable models. + * @return {!Array.} List of variable models. */ Blockly.VariableMap.prototype.getAllVariables = function() { var all_variables = []; diff --git a/core/variable_model.js b/core/variable_model.js index 990702a9b..4dd4879cf 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -31,14 +31,14 @@ goog.require('goog.string'); /** * Class for a variable model. - * Holds information for the variable including name, id, and type. + * Holds information for the variable including name, ID, and type. * @param {!Blockly.Workspace} workspace The variable's workspace. * @param {!string} name The name of the variable. This must be unique across * variables and procedures. - * @param {?string} opt_type The type of the variable like 'int' or 'string'. + * @param {string=} opt_type The type of the variable like 'int' or 'string'. * Does not need to be unique. Field_variable can filter variables based on * 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 + * @param {string=} opt_id The unique ID of the variable. This will default to * a UUID. * @see {Blockly.FieldVariable} * @constructor @@ -80,7 +80,7 @@ Blockly.VariableModel = function(workspace, name, opt_type, opt_id) { }; /** - * @return {!string} The id for the variable. + * @return {!string} The ID for the variable. */ Blockly.VariableModel.prototype.getId = function() { return this.id_; diff --git a/core/variables.js b/core/variables.js index 5b37a7000..3be7e41c6 100644 --- a/core/variables.js +++ b/core/variables.js @@ -232,7 +232,7 @@ Blockly.Variables.generateUniqueName = function(workspace) { * @param {function(?string=)=} opt_callback A callback. It will * be passed an acceptable new variable name, or null if change is to be * aborted (cancel button), or undefined if an existing variable was chosen. - * @param {?string} opt_type The type of the variable like 'int', 'string', or + * @param {string=} opt_type The type of the variable like 'int', 'string', or * ''. This will default to '', which is a specific type. */ Blockly.Variables.createVariable = function(workspace, opt_callback, opt_type) { diff --git a/core/workspace.js b/core/workspace.js index 614f2fe6a..e10e7d364 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -34,7 +34,7 @@ goog.require('goog.math'); /** * Class for a workspace. This is a data structure that contains blocks. * There is no UI, and can be created headlessly. - * @param {Blockly.Options} opt_options Dictionary of options. + * @param {!Blockly.Options=} opt_options Dictionary of options. * @constructor */ Blockly.Workspace = function(opt_options) { @@ -285,8 +285,8 @@ Blockly.Workspace.prototype.renameVariable = function(oldName, newName) { /** * Rename a variable by updating its name in the variable map. Identify the - * variable to rename with the given id. - * @param {string} id Id of the variable to rename. + * variable to rename with the given ID. + * @param {string} id ID of the variable to rename. * @param {string} newName New variable name. */ Blockly.Workspace.prototype.renameVariableById = function(id, newName) { @@ -295,13 +295,13 @@ Blockly.Workspace.prototype.renameVariableById = function(id, newName) { }; /** - * Create a variable with a given name, optional type, and optional id. + * Create a variable with a given name, optional type, and optional ID. * @param {!string} name The name of the variable. This must be unique across * variables and procedures. - * @param {?string} opt_type The type of the variable like 'int' or 'string'. + * @param {string=} opt_type The type of the variable like 'int' or 'string'. * Does not need to be unique. Field_variable can filter variables based on * 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 + * @param {string=} opt_id The unique ID of the variable. This will default to * a UUID. * @return {?Blockly.VariableModel} The newly created variable. */ @@ -358,7 +358,8 @@ Blockly.Workspace.prototype.deleteVariable = function(name) { if (uses.length > 1) { // Confirm before deleting multiple blocks. Blockly.confirm( - Blockly.Msg.DELETE_VARIABLE_CONFIRMATION.replace('%1', uses.length). + Blockly.Msg.DELETE_VARIABLE_CONFIRMATION.replace('%1', + String(uses.length)). replace('%2', name), function(ok) { if (ok) { @@ -372,23 +373,23 @@ Blockly.Workspace.prototype.deleteVariable = function(name) { }; /** - * Delete a variables by the passed in id and all of its uses from this + * Delete a variables by the passed in ID and all of its uses from this * workspace. May prompt the user for confirmation. - * @param {string} id Id of variable to delete. + * @param {string} id ID of variable to delete. */ Blockly.Workspace.prototype.deleteVariableById = function(id) { var variable = this.getVariableById(id); if (variable) { this.deleteVariableInternal_(variable); } else { - console.warn("Can't delete non-existant variable: " + id); + console.warn("Can't delete non-existent variable: " + id); } }; /** * Deletes a variable and all of its uses from this workspace without asking the * user for confirmation. - * @param {Blockly.VariableModel} variable Variable to delete. + * @param {!Blockly.VariableModel} variable Variable to delete. * @private */ Blockly.Workspace.prototype.deleteVariableInternal_ = function(variable) { @@ -426,10 +427,10 @@ Blockly.Workspace.prototype.getVariable = function(name) { }; /** - * Find the variable by the given id and return it. Return null if it is not + * Find the variable by the given ID and return it. Return null if it is not * found. - * @param {!string} id The id to check for. - * @return {?Blockly.VariableModel} The variable with the given id. + * @param {!string} id The ID to check for. + * @return {?Blockly.VariableModel} The variable with the given ID. */ Blockly.Workspace.prototype.getVariableById = function(id) { return this.variableMap_.getVariableById(id); @@ -450,7 +451,7 @@ Blockly.Workspace.prototype.getWidth = function() { * @param {?string} prototypeName Name of the language object containing * type-specific functions for this block. * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise - * create a new id. + * create a new ID. * @return {!Blockly.Block} The created block. */ Blockly.Workspace.prototype.newBlock = function(prototypeName, opt_id) { diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 8b746a360..7b2c4cc96 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -27,10 +27,12 @@ goog.provide('Blockly.WorkspaceAudio'); + /** * Class for loading, storing, and playing audio for a workspace. * @param {Blockly.WorkspaceSvg} parentWorkspace The parent of the workspace * this audio object belongs to, or null. + * @constructor */ Blockly.WorkspaceAudio = function(parentWorkspace) { @@ -107,7 +109,7 @@ Blockly.WorkspaceAudio.prototype.load = function(filenames, name) { Blockly.WorkspaceAudio.prototype.preload = function() { for (var name in this.SOUNDS_) { var sound = this.SOUNDS_[name]; - sound.volume = .01; + sound.volume = 0.01; sound.play(); sound.pause(); // iOS can only process one sound at a time. Trying to load more than one diff --git a/core/workspace_svg.js b/core/workspace_svg.js index d7d78793f..522253f66 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -245,7 +245,7 @@ Blockly.WorkspaceSvg.prototype.lastRecordedPageScroll_ = null; /** * Map from function names to callbacks, for deciding what to do when a button * is clicked. - * @type {!Object} + * @type {!Object.} * @private */ Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_ = {}; @@ -253,7 +253,7 @@ Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_ = {}; /** * Map from function names to callbacks, for deciding what to do when a custom * toolbox category is opened. - * @type {!Object>} + * @type {!Object.>} * @private */ Blockly.WorkspaceSvg.prototype.toolboxCategoryCallbacks_ = {}; @@ -370,10 +370,10 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) { } /** @type {SVGElement} */ this.svgBlockCanvas_ = Blockly.utils.createSvgElement('g', - {'class': 'blocklyBlockCanvas'}, this.svgGroup_, this); + {'class': 'blocklyBlockCanvas'}, this.svgGroup_); /** @type {SVGElement} */ this.svgBubbleCanvas_ = Blockly.utils.createSvgElement('g', - {'class': 'blocklyBubbleCanvas'}, this.svgGroup_, this); + {'class': 'blocklyBubbleCanvas'}, this.svgGroup_); var bottom = Blockly.Scrollbar.scrollbarThickness; if (this.options.hasTrashcan) { bottom = this.addTrashcan_(bottom); @@ -652,7 +652,7 @@ Blockly.WorkspaceSvg.prototype.getBubbleCanvas = function() { /** * Get the SVG element that contains this workspace. - * @return {!Element} SVG element. + * @return {Element} SVG element. */ Blockly.WorkspaceSvg.prototype.getParentSvg = function() { if (this.cachedParentSvg_) { @@ -664,7 +664,7 @@ Blockly.WorkspaceSvg.prototype.getParentSvg = function() { this.cachedParentSvg_ = element; return element; } - element = element.parentNode; + element = element.parentElement; } return null; }; @@ -933,7 +933,7 @@ Blockly.WorkspaceSvg.prototype.renameVariable = function(oldName, newName) { /** * Rename a variable by updating its name in the variable map. Update the * flyout to show the renamed variable immediately. - * @param {string} id Id of the variable to rename. + * @param {string} id ID of the variable to rename. * @param {string} newName New variable name. * @package */ @@ -954,9 +954,9 @@ Blockly.WorkspaceSvg.prototype.deleteVariable = function(name) { }; /** - * Delete a variable by the passed in id. Update the flyout to show + * Delete a variable by the passed in ID. Update the flyout to show * immediately that the variable is deleted. - * @param {string} id Id of variable to delete. + * @param {string} id ID of variable to delete. * @package */ Blockly.WorkspaceSvg.prototype.deleteVariableById = function(id) { @@ -971,7 +971,7 @@ Blockly.WorkspaceSvg.prototype.deleteVariableById = function(id) { * @param {string=} opt_type The type of the variable like 'int' or 'string'. * Does not need to be unique. Field_variable can filter variables based on * 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 + * @param {string=} opt_id The unique ID of the variable. This will default to * a UUID. * @return {?Blockly.VariableModel} The newly created variable. * @package @@ -1064,7 +1064,7 @@ Blockly.WorkspaceSvg.prototype.moveDrag = function(e) { * @return {boolean} True if currently dragging or scrolling. */ Blockly.WorkspaceSvg.prototype.isDragging = function() { - return this.currentGesture_ && this.currentGesture_.isDragging(); + return this.currentGesture_ != null && this.currentGesture_.isDragging(); }; /** @@ -1785,7 +1785,7 @@ Blockly.WorkspaceSvg.prototype.removeButtonCallback = function(key) { * custom toolbox categories in this workspace. See the variable and procedure * categories as an example. * @param {string} key The name to use to look up this function. - * @param {function(!Blockly.Workspace):!Array} func The function to + * @param {function(!Blockly.Workspace):!Array.} func The function to * call when the given toolbox category is opened. */ Blockly.WorkspaceSvg.prototype.registerToolboxCategoryCallback = function(key, @@ -1799,7 +1799,7 @@ Blockly.WorkspaceSvg.prototype.registerToolboxCategoryCallback = function(key, * Get the callback function associated with a given key, for populating * custom toolbox categories in this workspace. * @param {string} key The name to use to look up the function. - * @return {?function(!Blockly.Workspace):!Array} The function + * @return {?function(!Blockly.Workspace):!Array.} The function * corresponding to the given key for this workspace, or null if no function * is registered. */ diff --git a/core/xml.js b/core/xml.js index 03f26bef1..debe77c59 100644 --- a/core/xml.js +++ b/core/xml.js @@ -37,7 +37,7 @@ goog.require('goog.dom'); /** * Encode a block tree as XML. * @param {!Blockly.Workspace} workspace The workspace containing blocks. - * @param {boolean} opt_noId True if the encoder should skip the block ids. + * @param {boolean=} opt_noId True if the encoder should skip the block IDs. * @return {!Element} XML document. */ Blockly.Xml.workspaceToDom = function(workspace, opt_noId) { @@ -70,7 +70,7 @@ Blockly.Xml.variablesToDom = function(variableList) { /** * Encode a block subtree as XML with XY coordinates. * @param {!Blockly.Block} block The root block to encode. - * @param {boolean} opt_noId True if the encoder should skip the block id. + * @param {boolean=} opt_noId True if the encoder should skip the block ID. * @return {!Element} Tree of XML elements. */ Blockly.Xml.blockToDomWithXY = function(block, opt_noId) { @@ -89,7 +89,7 @@ Blockly.Xml.blockToDomWithXY = function(block, opt_noId) { /** * Encode a block subtree as XML. * @param {!Blockly.Block} block The root block to encode. - * @param {boolean} opt_noId True if the encoder should skip the block id. + * @param {boolean=} opt_noId True if the encoder should skip the block ID. * @return {!Element} Tree of XML elements. */ Blockly.Xml.blockToDom = function(block, opt_noId) { @@ -303,7 +303,7 @@ Blockly.Xml.textToDom = function(text) { * Decode an XML DOM and create blocks on the workspace. * @param {!Element} xml XML DOM. * @param {!Blockly.Workspace} workspace The workspace. - * @return {Array.} An array containing new block ids. + * @return {Array.} An array containing new block IDs. */ Blockly.Xml.domToWorkspace = function(xml, workspace) { if (xml instanceof Blockly.Workspace) { @@ -317,7 +317,7 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) { if (workspace.RTL) { width = workspace.getWidth(); } - var newBlockIds = []; // A list of block ids added by this call. + var newBlockIds = []; // A list of block IDs added by this call. Blockly.Field.startCache(); // Safari 7.1.3 is known to provide node lists with extra references to // children beyond the lists' length. Trust the length, do not use the @@ -385,12 +385,12 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) { * blocks immediately below prior blocks, aligned by their starting edge. * @param {!Element} xml The XML DOM. * @param {!Blockly.Workspace} workspace The workspace to add to. - * @return {Array.} An array containing new block ids. + * @return {Array.} An array containing new block IDs. */ Blockly.Xml.appendDomToWorkspace = function(xml, workspace) { - var bbox; //bounding box of the current blocks - // first check if we have a workspaceSvg otherwise the block have no shape - // and the position does not matter + var bbox; // Bounding box of the current blocks. + // First check if we have a workspaceSvg, otherwise the blocks have no shape + // and the position does not matter. if (workspace.hasOwnProperty('scale')) { var savetab = Blockly.BlockSvg.TAB_WIDTH; try { @@ -400,22 +400,22 @@ Blockly.Xml.appendDomToWorkspace = function(xml, workspace) { Blockly.BlockSvg.TAB_WIDTH = savetab; } } - // load the new blocks into the workspace and get the ids of the new blocks + // Load the new blocks into the workspace and get the IDs of the new blocks. var newBlockIds = Blockly.Xml.domToWorkspace(xml,workspace); - if (bbox && bbox.height) { // check if any previous block - var offsetY = 0; // offset to add to y of the new block + if (bbox && bbox.height) { // check if any previous block + var offsetY = 0; // offset to add to y of the new block var offsetX = 0; - var farY = bbox.y + bbox.height; //bottom position - var topX = bbox.x; // x of bounding box - // check position of the new blocks - var newX = Infinity; // x of top corner - var newY = Infinity; // y of top corner + var farY = bbox.y + bbox.height; // bottom position + var topX = bbox.x; // x of bounding box + // Check position of the new blocks. + var newX = Infinity; // x of top corner + var newY = Infinity; // y of top corner for (var i = 0; i < newBlockIds.length; i++) { var blockXY = workspace.getBlockById(newBlockIds[i]).getRelativeToSurfaceXY(); if (blockXY.y < newY) { newY = blockXY.y; } - if (blockXY.x < newX) { //if we align also on x + if (blockXY.x < newX) { // if we align also on x newX = blockXY.x; } } @@ -530,21 +530,21 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { var input; // Find any enclosed blocks or shadows in this tag. - var childBlockNode = null; - var childShadowNode = null; + var childBlockElement = null; + var childShadowElement = null; for (var j = 0, grandchildNode; grandchildNode = xmlChild.childNodes[j]; j++) { if (grandchildNode.nodeType == 1) { if (grandchildNode.nodeName.toLowerCase() == 'block') { - childBlockNode = grandchildNode; + childBlockElement = /** @type {!Element} */ (grandchildNode); } else if (grandchildNode.nodeName.toLowerCase() == 'shadow') { - childShadowNode = grandchildNode; + childShadowElement = /** @type {!Element} */ (grandchildNode); } } } // Use the shadow block if there is no child block. - if (!childBlockNode && childShadowNode) { - childBlockNode = childShadowNode; + if (!childBlockElement && childShadowElement) { + childBlockElement = childShadowElement; } var name = xmlChild.getAttribute('name'); @@ -589,8 +589,8 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { var text = xmlChild.textContent; if (field instanceof Blockly.FieldVariable) { // TODO (marisaleung): When we change setValue and getValue to - // interact with id's instead of names, update this so that we get - // the variable based on id instead of textContent. + // interact with IDs instead of names, update this so that we get + // the variable based on ID instead of textContent. var type = xmlChild.getAttribute('variableType') || ''; var variable = workspace.getVariable(text); if (!variable) { @@ -619,11 +619,11 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { prototypeName); break; } - if (childShadowNode) { - input.connection.setShadowDom(childShadowNode); + if (childShadowElement) { + input.connection.setShadowDom(childShadowElement); } - if (childBlockNode) { - blockChild = Blockly.Xml.domToBlockHeadless_(childBlockNode, + if (childBlockElement) { + blockChild = Blockly.Xml.domToBlockHeadless_(childBlockElement, workspace); if (blockChild.outputConnection) { input.connection.connect(blockChild.outputConnection); @@ -636,16 +636,16 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { } break; case 'next': - if (childShadowNode && block.nextConnection) { - block.nextConnection.setShadowDom(childShadowNode); + if (childShadowElement && block.nextConnection) { + block.nextConnection.setShadowDom(childShadowElement); } - if (childBlockNode) { + if (childBlockElement) { goog.asserts.assert(block.nextConnection, 'Next statement does not exist.'); // If there is more than one XML 'next' tag. goog.asserts.assert(!block.nextConnection.isConnected(), 'Next statement is already connected.'); - blockChild = Blockly.Xml.domToBlockHeadless_(childBlockNode, + blockChild = Blockly.Xml.domToBlockHeadless_(childBlockElement, workspace); goog.asserts.assert(blockChild.previousConnection, 'Next block does not have previous statement.'); diff --git a/tests/jsunit/input_test.js b/tests/jsunit/input_test.js index 684bef43d..35bdd4f30 100644 --- a/tests/jsunit/input_test.js +++ b/tests/jsunit/input_test.js @@ -19,8 +19,8 @@ */ /** - * @fileoverview Tests for Blockly.Input - */ + * @fileoverview Tests for Blockly.Input + */ 'use strict'; function test_appendField_simple() { @@ -157,7 +157,7 @@ function test_insertFieldAt_prefix() { var after = new Blockly.FieldLabel('after'); var prefix = new Blockly.FieldLabel('prefix'); var between = new Blockly.FieldLabel('between'); - between.prefixField = prefix + between.prefixField = prefix; input.appendField(before); input.appendField(after); @@ -175,7 +175,7 @@ function test_insertFieldAt_prefix() { assertEquals(after, input.fieldRow[3]); } -function test_insertFieldAt_prefix() { +function test_insertFieldAt_suffix() { var ws = new Blockly.Workspace(); var block = new Blockly.Block(ws); var input = new Blockly.Input(Blockly.DUMMY_INPUT, 'INPUT', block); @@ -183,7 +183,7 @@ function test_insertFieldAt_prefix() { var after = new Blockly.FieldLabel('after'); var suffix = new Blockly.FieldLabel('suffix'); var between = new Blockly.FieldLabel('between'); - between.suffixField = suffix + between.suffixField = suffix; input.appendField(before); input.appendField(after);