From 98617d8ddc15dd1fd6ee7a8c58d810a83e2b03fd Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 22 Jun 2016 12:56:56 -0700 Subject: [PATCH] Move tokenizeIntepolation into Blockly.utils namespace. --- core/block.js | 2 +- core/blockly.js | 3 ++- core/utils.js | 2 +- tests/jsunit/blockly_test.js | 14 +++++++------- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/block.js b/core/block.js index 36a703171..584a9fa56 100644 --- a/core/block.js +++ b/core/block.js @@ -1021,7 +1021,7 @@ Blockly.Block.prototype.jsonInit = function(json) { * @private */ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) { - var tokens = Blockly.tokenizeInterpolation(message); + var tokens = Blockly.utils.tokenizeInterpolation(message); // Interpolate the arguments. Build a list of elements. var indexDup = []; var indexCount = 0; diff --git a/core/blockly.js b/core/blockly.js index 4fd5de0ca..c51191b08 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -549,7 +549,8 @@ Blockly.addChangeListener = function(func) { /** * Returns the main workspace. Returns the last used main workspace (based on - * focus). + * focus). Try not to use this function, particularly if there are multiple + * Blockly instances on a page. * @return {!Blockly.Workspace} The main workspace. */ Blockly.getMainWorkspace = function() { diff --git a/core/utils.js b/core/utils.js index 89644fff9..fe13572ac 100644 --- a/core/utils.js +++ b/core/utils.js @@ -423,7 +423,7 @@ Blockly.isNumber = function(str) { * @param {string} message Text containing interpolation tokens. * @return {!Array.} Array of strings and numbers. */ -Blockly.tokenizeInterpolation = function(message) { +Blockly.utils.tokenizeInterpolation = function(message) { var tokens = []; var chars = message.split(''); chars.push(''); // End marker. diff --git a/tests/jsunit/blockly_test.js b/tests/jsunit/blockly_test.js index 88f0cebaa..0278b8442 100644 --- a/tests/jsunit/blockly_test.js +++ b/tests/jsunit/blockly_test.js @@ -123,18 +123,18 @@ function test_commonWordSuffix() { } function test_tokenizeInterpolation() { - var tokens = Blockly.tokenizeInterpolation(''); + var tokens = Blockly.utils.tokenizeInterpolation(''); assertArrayEquals('Null interpolation', [], tokens); - tokens = Blockly.tokenizeInterpolation('Hello'); + tokens = Blockly.utils.tokenizeInterpolation('Hello'); assertArrayEquals('No interpolation', ['Hello'], tokens); - tokens = Blockly.tokenizeInterpolation('Hello%World'); + tokens = Blockly.utils.tokenizeInterpolation('Hello%World'); assertArrayEquals('Unescaped %.', ['Hello%World'], tokens); - tokens = Blockly.tokenizeInterpolation('Hello%%World'); + tokens = Blockly.utils.tokenizeInterpolation('Hello%%World'); assertArrayEquals('Escaped %.', ['Hello%World'], tokens); - tokens = Blockly.tokenizeInterpolation('Hello %1 World'); + tokens = Blockly.utils.tokenizeInterpolation('Hello %1 World'); assertArrayEquals('Interpolation.', ['Hello ', 1, ' World'], tokens); - tokens = Blockly.tokenizeInterpolation('%123Hello%456World%789'); + tokens = Blockly.utils.tokenizeInterpolation('%123Hello%456World%789'); assertArrayEquals('Interpolations.', [123, 'Hello', 456, 'World', 789], tokens); - tokens = Blockly.tokenizeInterpolation('%%%x%%0%00%01%'); + tokens = Blockly.utils.tokenizeInterpolation('%%%x%%0%00%01%'); assertArrayEquals('Torture interpolations.', ['%%x%0', 0, 1, '%'], tokens); }