diff --git a/core/block.js b/core/block.js index dd44dce1d..895c77c1b 100644 --- a/core/block.js +++ b/core/block.js @@ -1814,7 +1814,7 @@ Blockly.Block.prototype.getInputTargetBlock = function(name) { /** * Returns the comment on this block (or null if there is no comment). - * @return {string} Block's comment. + * @return {?string} Block's comment. */ Blockly.Block.prototype.getCommentText = function() { return this.commentModel.text; diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index ffdf54729..5c33b5273 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -173,7 +173,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { * @return {!Blockly.utils.Coordinate} Current translation of the surface. */ Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { - var xy = Blockly.utils.getRelativeXY(this.SVG_); + var xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); }; @@ -189,11 +189,11 @@ Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() { /** * Get the current blocks on the drag surface, if any (primarily * for BlockSvg.getRelativeToSurfaceXY). - * @return {!Element|undefined} Drag surface block DOM element, or undefined - * if no blocks exist. + * @return {Element} Drag surface block DOM element, or undefined if no blocks + * exist. */ Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { - return this.dragGroup_.firstChild; + return /** @type {Element} */ (this.dragGroup_.firstChild); }; /** diff --git a/core/block_svg.js b/core/block_svg.js index 7119d7d23..5c34f64ae 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -56,7 +56,7 @@ goog.require('Blockly.Warning'); Blockly.BlockSvg = function(workspace, prototypeName, opt_id) { // Create core elements for the block. /** - * @type {SVGElement} + * @type {!SVGElement} * @private */ this.svgGroup_ = Blockly.utils.dom.createSvgElement('g', {}, null); @@ -440,7 +440,7 @@ Blockly.BlockSvg.prototype.getRelativeToSurfaceXY = function() { x += surfaceTranslation.x; y += surfaceTranslation.y; } - element = element.parentNode; + element = /** @type {!SVGElement} */ (element.parentNode); } while (element && element != this.workspace.getCanvas() && element != dragSurfaceGroup); } @@ -997,7 +997,7 @@ Blockly.BlockSvg.prototype.setInsertionMarker = function(insertionMarker) { /** * Return the root node of the SVG or null if none exists. - * @return {SVGElement} The root SVG node (probably a group). + * @return {!SVGElement} The root SVG node (probably a group). */ Blockly.BlockSvg.prototype.getSvgRoot = function() { return this.svgGroup_; diff --git a/core/blockly.js b/core/blockly.js index 02966ed09..11513dddc 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -363,7 +363,7 @@ Blockly.hideChaff = function(opt_allowToolbox) { * @return {!Blockly.Workspace} The main workspace. */ Blockly.getMainWorkspace = function() { - return Blockly.mainWorkspace; + return /** @type {!Blockly.Workspace} */ (Blockly.mainWorkspace); }; /** @@ -396,7 +396,7 @@ Blockly.confirm = function(message, callback) { * recommend testing mobile when overriding this. * @param {string} message The message to display to the user. * @param {string} defaultValue The value to initialize the prompt with. - * @param {!function(string)} callback The callback for handling user response. + * @param {!function(?string)} callback The callback for handling user response. */ Blockly.prompt = function(message, defaultValue, callback) { callback(prompt(message, defaultValue)); diff --git a/core/contextmenu.js b/core/contextmenu.js index 10330e9ff..48aa337ea 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -279,7 +279,7 @@ Blockly.ContextMenu.blockCommentOption = function(block) { enabled: !Blockly.utils.userAgent.IE }; // If there's already a comment, add an option to delete it. - if (block.comment) { + if (block.getCommentIcon()) { commentOption.text = Blockly.Msg['REMOVE_COMMENT']; commentOption.callback = function() { block.setCommentText(null); diff --git a/core/events.js b/core/events.js index f52a838c2..d58771afa 100644 --- a/core/events.js +++ b/core/events.js @@ -391,7 +391,7 @@ Blockly.Events.fromJson = function(json, workspace) { event = new Blockly.Events.CommentDelete(null); break; case Blockly.Events.FINISHED_LOADING: - event = new Blockly.Events.FinishedLoading(null); + event = new Blockly.Events.FinishedLoading(workspace); break; default: throw Error('Unknown event type.'); diff --git a/core/extensions.js b/core/extensions.js index 3f43a3ca8..c410bb3e9 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -87,7 +87,7 @@ Blockly.Extensions.registerMixin = function(name, mixinObj) { * @param {!Object} mixinObj The values to mix in. * @param {(function())=} opt_helperFn An optional function to apply after * mixing in the object. - * @param {Array.=} opt_blockList A list of blocks to appear in the + * @param {!Array.=} opt_blockList A list of blocks to appear in the * flyout of the mutator dialog. * @throws {Error} if the mutation is invalid or can't be applied to the block. */ @@ -114,7 +114,7 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, if (!Blockly.Mutator) { throw Error(errorPrefix + 'Missing require for Blockly.Mutator'); } - this.setMutator(new Blockly.Mutator(opt_blockList)); + this.setMutator(new Blockly.Mutator(opt_blockList || [])); } // Mixin the object. this.mixin(mixinObj); @@ -165,7 +165,8 @@ Blockly.Extensions.apply = function(name, block, isMutator) { var errorPrefix = 'Error after applying mutator "' + name + '": '; Blockly.Extensions.checkBlockHasMutatorProperties_(errorPrefix, block); } else { - if (!Blockly.Extensions.mutatorPropertiesMatch_(mutatorProperties, block)) { + if (!Blockly.Extensions.mutatorPropertiesMatch_( + /** @type {!Array.} */ (mutatorProperties), block)) { throw Error('Error when applying extension "' + name + '": ' + 'mutation properties changed when applying a non-mutator extension.'); } @@ -359,7 +360,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, } this.setTooltip(function() { - var value = this.getFieldValue(dropdownName); + var value = String(this.getFieldValue(dropdownName)); var tooltip = lookupTable[value]; if (tooltip == null) { if (blockTypesChecked.indexOf(this.type) == -1) { diff --git a/core/grid.js b/core/grid.js index 3b036f493..72367c10b 100644 --- a/core/grid.js +++ b/core/grid.js @@ -64,14 +64,15 @@ Blockly.Grid = function(pattern, options) { * @type {SVGElement} * @private */ - this.line1_ = pattern.firstChild; + this.line1_ = /** @type {SVGElement} */ (pattern.firstChild); /** * The vertical grid line, if it exists. * @type {SVGElement} * @private */ - this.line2_ = this.line1_ && this.line1_.nextSibling; + this.line2_ = this.line1_ && + (/** @type {SVGElement} */ (this.line1_.nextSibling)); /** * Whether blocks should snap to the grid. @@ -154,7 +155,7 @@ Blockly.Grid.prototype.update = function(scale) { /** * Set the attributes on one of the lines in the grid. Use this to update the * length and stroke width of the grid lines. - * @param {!SVGElement} line Which line to update. + * @param {SVGElement} line Which line to update. * @param {number} width The new stroke size (in px). * @param {number} x1 The new x start position of the line (in px). * @param {number} x2 The new x end position of the line (in px). diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index ed74df6a7..2721b8c4e 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -293,7 +293,7 @@ Blockly.ASTNode.prototype.findNextForField_ = function() { var location = /** @type {!Blockly.Field} */ (this.location_); var input = location.getParentInput(); var block = location.getSourceBlock(); - var curIdx = block.inputList.indexOf(input); + var curIdx = block.inputList.indexOf(/** @type {!Blockly.Input} */ (input)); var fieldIdx = input.fieldRow.indexOf(location) + 1; for (var i = curIdx, newInput; newInput = block.inputList[i]; i++) { var fieldRow = newInput.fieldRow; @@ -347,7 +347,8 @@ Blockly.ASTNode.prototype.findPrevForField_ = function() { var location = /** @type {!Blockly.Field} */ (this.location_); var parentInput = location.getParentInput(); var block = location.getSourceBlock(); - var curIdx = block.inputList.indexOf(parentInput); + var curIdx = block.inputList.indexOf( + /** @type {!Blockly.Input} */ (parentInput)); var fieldIdx = parentInput.fieldRow.indexOf(location) - 1; for (var i = curIdx, input; input = block.inputList[i]; i--) { if (input.connection && input !== parentInput) { diff --git a/core/workspace.js b/core/workspace.js index 59a5e845a..2119c8d17 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -109,7 +109,7 @@ Blockly.Workspace = function(opt_options) { * A FieldVariable must always refer to a Blockly.VariableModel. We reconcile * these by tracking "potential" variables in the flyout. These variables * become real when references to them are dragged into the main workspace. - * @type {!Blockly.VariableMap} + * @type {Blockly.VariableMap} * @private */ this.potentialVariableMap_ = null; @@ -246,9 +246,11 @@ Blockly.Workspace.prototype.refreshTheme = function() { Blockly.Workspace.prototype.updateBlockStyles_ = function(blocks) { for (var i = 0, block; block = blocks[i]; i++) { var blockStyleName = block.getStyleName(); - block.setStyle(blockStyleName); - if (block.mutator) { - block.mutator.updateBlockStyle(blockStyleName); + if (blockStyleName) { + block.setStyle(blockStyleName); + if (block.mutator) { + block.mutator.updateBlockStyle(); + } } } }; @@ -861,7 +863,7 @@ Blockly.Workspace.prototype.createPotentialVariableMap = function() { /** * Return the map of all variables on the workspace. - * @return {Blockly.VariableMap} The variable map. + * @return {!Blockly.VariableMap} The variable map. */ Blockly.Workspace.prototype.getVariableMap = function() { return this.variableMap_; @@ -869,7 +871,7 @@ Blockly.Workspace.prototype.getVariableMap = function() { /** * Set the map of all variables on the workspace. - * @param {Blockly.VariableMap} variableMap The variable map. + * @param {!Blockly.VariableMap} variableMap The variable map. * @package */ Blockly.Workspace.prototype.setVariableMap = function(variableMap) { diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 256cd5166..1c24f742b 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -48,7 +48,6 @@ Blockly.WorkspaceAudio = function(parentWorkspace) { /** * Database of pre-loaded sounds. * @private - * @const */ this.SOUNDS_ = Object.create(null); }; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index aee610986..8c676431a 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -531,7 +531,7 @@ Blockly.WorkspaceSvg.prototype.isVisible = function() { * Return the absolute coordinates of the top-left corner of this element, * scales that after canvas SVG element, if it's a descendant. * The origin (0,0) is the top-left corner of the Blockly SVG. - * @param {!Element} element Element to find the coordinates of. + * @param {!SVGElement} element SVG element to find the coordinates of. * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. * @package */ @@ -554,7 +554,7 @@ Blockly.WorkspaceSvg.prototype.getSvgXY = function(element) { } x += xy.x * scale; y += xy.y * scale; - element = /** @type {!Element} */ (element.parentNode); + element = /** @type {!SVGElement} */ (element.parentNode); } while (element && element != this.getParentSvg()); return new Blockly.utils.Coordinate(x, y); }; @@ -1335,7 +1335,7 @@ Blockly.WorkspaceSvg.prototype.deleteVariableById = function(id) { * 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. * @package */ Blockly.WorkspaceSvg.prototype.createVariable = function(name, @@ -1420,7 +1420,8 @@ Blockly.WorkspaceSvg.prototype.moveDrag = function(e) { // Fix scale of mouse event. point.x /= this.scale; point.y /= this.scale; - return Blockly.utils.Coordinate.sum(this.dragDeltaXY_, point); + return Blockly.utils.Coordinate.sum( + /** @type {!Blockly.utils.Coordinate} */ (this.dragDeltaXY_), point); }; /**