diff --git a/core/block.js b/core/block.js index e68f5db5c..4ad3117b0 100644 --- a/core/block.js +++ b/core/block.js @@ -1220,18 +1220,10 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) { */ Blockly.Block.newFieldImageFromJson_ = function(options) { var src = Blockly.utils.replaceMessageReferences(options['src']); - var width = options['width']; - if (goog.isString(width)) { - width = Number(Blockly.utils.replaceMessageReferences(width)); - } - var height = options['height']; - if (goog.isString(height)) { - height = Number(Blockly.utils.replaceMessageReferences(height)); - } - var alt = options['alt']; - if (goog.isString(alt)) { - alt = Blockly.utils.replaceMessageReferences(alt); - } + var width = Number(Blockly.utils.replaceMessageReferences(options['width'])); + var height = + Number(Blockly.utils.replaceMessageReferences(options['height'])); + var alt = Blockly.utils.replaceMessageReferences(options['alt']); return new Blockly.FieldImage(src, width, height, alt); }; @@ -1272,10 +1264,7 @@ Blockly.Block.newFieldTextInputFromJson_ = function(options) { * @private */ Blockly.Block.newFieldVariableFromJson_ = function(options) { - var varname = options['variable']; - if (goog.isString(varname)) { - varname = Blockly.utils.replaceMessageReferences(varname); - } + var varname = Blockly.utils.replaceMessageReferences(options['variable']); return new Blockly.FieldVariable(varname); }; diff --git a/core/utils.js b/core/utils.js index 5066c34f4..b4928044e 100644 --- a/core/utils.js +++ b/core/utils.js @@ -259,7 +259,7 @@ Blockly.utils.getRelativeXY.XY_2D_REGEX_ = * context (scale...). * @return {!SVGElement} Newly created SVG element. */ -Blockly.utils.createSvgElement = function(name, attrs, parent, opt_workspace) { +Blockly.utils.createSvgElement = function(name, attrs, parent /*, opt_workspace */) { var e = /** @type {!SVGElement} */ ( document.createElementNS(Blockly.SVG_NS, name)); for (var key in attrs) { @@ -409,13 +409,17 @@ Blockly.utils.tokenizeInterpolation = function(message) { }; /** - * Replaces string table references in a message string. For example, - * %{bky_my_msg} and %{BKY_MY_MSG} will both be replaced with the value in - * Blockly.Msg['MY_MSG']. - * @param {string} message Text which might contain string table references. + * Replaces string table references in a message, if the message is a string. + * For example, "%{bky_my_msg}" and "%{BKY_MY_MSG}" will both be replaced with + * the value in Blockly.Msg['MY_MSG']. + * @param {string|?} message Message, which may be a string that contains + * string table references. * @return {!string} String with message references replaced. */ Blockly.utils.replaceMessageReferences = function(message) { + if (!goog.isString(message)) { + return message; + } var interpolatedResult = Blockly.utils.tokenizeInterpolation_(message, false); // When parseInterpolationTokens == false, interpolatedResult should be at // most length 1.