From b32136d81f1a51c42ef2252e043b0b972c4b3e0e Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Tue, 14 Feb 2017 15:51:24 -0800 Subject: [PATCH] Clarification update. Unraveling nested ternaries in Blockly.utils.tokenizeInterpolation_() --- core/utils.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/utils.js b/core/utils.js index b4928044e..641bb742c 100644 --- a/core/utils.js +++ b/core/utils.js @@ -535,10 +535,18 @@ Blockly.utils.tokenizeInterpolation_ = function(message, parseInterpolationToken keyUpper.substring(4) : null; if (bklyKey && bklyKey in Blockly.Msg) { var rawValue = Blockly.Msg[bklyKey]; - var subTokens = goog.isString(rawValue) ? - Blockly.utils.tokenizeInterpolation(rawValue) : - parseInterpolationTokens ? String(rawValue) : rawValue; - tokens = tokens.concat(subTokens); + if (goog.isString(rawValue)) { + // Attempt to dereference substrings, too, appending to the end. + Array.prototype.push.apply(tokens, + Blockly.utils.tokenizeInterpolation(rawValue)); + } else if (parseInterpolationTokens) { + // When parsing interpolation tokens, numbers are special + // placeholders (%1, %2, etc). Make sure all other values are + // strings. + tokens.push(String(rawValue)); + } else { + tokens.push(rawValue); + } } else { // No entry found in the string table. Pass reference as string. tokens.push('%{' + rawKey + '}');