diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index 01ed5b737..be9e2d48c 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -31,7 +31,7 @@ goog.provide('Blockly.Cursor'); * @constructor */ Blockly.Cursor = function() { - /* + /** * The current location of the cursor. * @type {Blockly.ASTNode} * @private diff --git a/core/ui_menu_utils.js b/core/ui_menu_utils.js index 35907e381..bd77bf750 100644 --- a/core/ui_menu_utils.js +++ b/core/ui_menu_utils.js @@ -39,7 +39,7 @@ goog.require('Blockly.utils.style'); */ Blockly.utils.uiMenu.getSize = function(menu) { var menuDom = menu.getElement(); - var menuSize = Blockly.utils.style.getSize(menuDom); + var menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; return menuSize; diff --git a/core/utils.js b/core/utils.js index 48f91e64e..f633f6c35 100644 --- a/core/utils.js +++ b/core/utils.js @@ -121,7 +121,7 @@ Blockly.utils.getInjectionDivXY_ = function(element) { if ((' ' + classes + ' ').indexOf(' injectionDiv ') != -1) { break; } - element = element.parentNode; + element = /** @type {!Element} */ (element.parentNode); } return new Blockly.utils.Coordinate(x, y); }; @@ -190,6 +190,7 @@ Blockly.utils.mouseToSvg = function(e, svg, matrix) { Blockly.utils.getScrollDeltaPixels = function(e) { switch (e.deltaMode) { case 0x00: // Pixel mode. + default: return { x: e.deltaX, y: e.deltaY @@ -236,7 +237,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 ? String(interpolatedResult[0]) : ''; }; /** diff --git a/core/utils/colour.js b/core/utils/colour.js index 849737448..928fc935b 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -38,8 +38,8 @@ goog.require('Blockly.utils'); * .parse('#f00') -> '#ff0000' * .parse('#ff0000') -> '#ff0000' * .parse('rgb(255, 0, 0)') -> '#ff0000' - * @param {string} str Colour in some CSS format. - * @return {string|null} A string containing a hex representation of the colour, + * @param {string|number} str Colour in some CSS format. + * @return {?string} A string containing a hex representation of the colour, * or null if can't be parsed. */ Blockly.utils.colour.parse = function(str) { @@ -166,11 +166,19 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { * @param {string} colour2 Second colour. * @param {number} factor The weight to be given to colour1 over colour2. * Values should be in the range [0, 1]. - * @return {string} Combined colour represented in hex. + * @return {?string} Combined colour represented in hex. */ Blockly.utils.colour.blend = function(colour1, colour2, factor) { - var rgb1 = Blockly.utils.colour.hexToRgb(Blockly.utils.colour.parse(colour1)); - var rgb2 = Blockly.utils.colour.hexToRgb(Blockly.utils.colour.parse(colour2)); + var hex1 = Blockly.utils.colour.parse(colour1); + if (!hex1) { + return null; + } + var hex2 = Blockly.utils.colour.parse(colour2); + if (!hex2) { + return null; + } + var rgb1 = Blockly.utils.colour.hexToRgb(hex1); + var rgb2 = Blockly.utils.colour.hexToRgb(hex2); var r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0])); var g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1])); var b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2]));