.utils.replaceMessageReferences(..) now gracefully returns non-string arguments.

This commit is contained in:
Andrew n marshall
2017-02-14 10:59:31 -08:00
parent 750c0300ec
commit afd1fdeb15
2 changed files with 14 additions and 21 deletions

View File

@@ -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);
};

View File

@@ -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.