From 78b8e2fa85aae38ca3c01ef7b194863a21c9071e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 13 Jul 2021 14:42:56 -0700 Subject: [PATCH 01/19] Migrate object.js to ES6 const/let --- core/utils/object.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/object.js b/core/utils/object.js index 3e95934d2..1317fd58b 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -46,7 +46,7 @@ Blockly.utils.object.inherits = function(childCtor, parentCtor) { * @param {!Object} source Source. */ Blockly.utils.object.mixin = function(target, source) { - for (var x in source) { + for (const x in source) { target[x] = source[x]; } }; @@ -58,7 +58,7 @@ Blockly.utils.object.mixin = function(target, source) { * @return {!Object} The resulting object. */ Blockly.utils.object.deepMerge = function(target, source) { - for (var x in source) { + for (const x in source) { if (source[x] != null && typeof source[x] === 'object') { target[x] = Blockly.utils.object.deepMerge( target[x] || Object.create(null), source[x]); From d224a2341deffc33d628d3da148cc7489ad9483e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 13 Jul 2021 15:30:56 -0700 Subject: [PATCH 02/19] Migrate object.js to goog.module --- core/utils/object.js | 21 ++++++++++++++------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/utils/object.js b/core/utils/object.js index 1317fd58b..ea7b3632a 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -14,7 +14,8 @@ * @name Blockly.utils.object * @namespace */ -goog.provide('Blockly.utils.object'); +goog.module('Blockly.utils.object'); +goog.module.declareLegacyNamespace(); /** @@ -23,7 +24,7 @@ goog.provide('Blockly.utils.object'); * @param {!Function} parentCtor Parent class. * @suppress {strictMissingProperties} superClass_ is not defined on Function. */ -Blockly.utils.object.inherits = function(childCtor, parentCtor) { +const inherits = function(childCtor, parentCtor) { // Set a .superClass_ property so that methods can call parent methods // without hard-coding the parent class name. // Could be replaced by ES6's super(). @@ -45,7 +46,7 @@ Blockly.utils.object.inherits = function(childCtor, parentCtor) { * @param {!Object} target Target. * @param {!Object} source Source. */ -Blockly.utils.object.mixin = function(target, source) { +const mixin = function(target, source) { for (const x in source) { target[x] = source[x]; } @@ -57,11 +58,10 @@ Blockly.utils.object.mixin = function(target, source) { * @param {!Object} source Source. * @return {!Object} The resulting object. */ -Blockly.utils.object.deepMerge = function(target, source) { +const deepMerge = function(target, source) { for (const x in source) { if (source[x] != null && typeof source[x] === 'object') { - target[x] = Blockly.utils.object.deepMerge( - target[x] || Object.create(null), source[x]); + target[x] = deepMerge(target[x] || Object.create(null), source[x]); } else { target[x] = source[x]; } @@ -74,7 +74,7 @@ Blockly.utils.object.deepMerge = function(target, source) { * @param {!Object} obj Object containing values. * @return {!Array} Array of values. */ -Blockly.utils.object.values = function(obj) { +const values = function(obj) { if (Object.values) { return Object.values(obj); } @@ -83,3 +83,10 @@ Blockly.utils.object.values = function(obj) { return obj[e]; }); }; + +exports = { + inherits, + mixin, + deepMerge, + values, +} \ No newline at end of file diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..01054cdfa 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -179,7 +179,7 @@ goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerato goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); -goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], []); +goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); From 632ef12ed577d0aa881b579b0e1625b20faf0e6e Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 18:45:34 -0700 Subject: [PATCH 03/19] Migrate core/utils/keycodes.js to goog.module --- core/utils/keycodes.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/utils/keycodes.js b/core/utils/keycodes.js index a5be94cb8..586d2f97e 100644 --- a/core/utils/keycodes.js +++ b/core/utils/keycodes.js @@ -16,7 +16,8 @@ * @name Blockly.utils.KeyCodes * @namespace */ -goog.provide('Blockly.utils.KeyCodes'); +goog.module('Blockly.utils.KeyCodes'); +goog.module.declareLegacyNamespace(); /** @@ -29,7 +30,7 @@ goog.provide('Blockly.utils.KeyCodes'); * * @enum {number} */ -Blockly.utils.KeyCodes = { +const KeyCodes = { WIN_KEY_FF_LINUX: 0, MAC_ENTER: 3, BACKSPACE: 8, @@ -166,3 +167,5 @@ Blockly.utils.KeyCodes = { // http://en.community.dell.com/support-forums/laptop/f/3518/p/19285957/19523128.aspx PHANTOM: 255 }; + +exports = KeyCodes; diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..45860bd0c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -176,7 +176,7 @@ goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecatio goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); -goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); +goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], []); From b92fba1a5a934d051be8e0e1fb9b4b8497c7ecf5 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 10:55:10 -0700 Subject: [PATCH 04/19] Fixed missing semicolon. --- core/utils/object.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/utils/object.js b/core/utils/object.js index ea7b3632a..dae55ec51 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -89,4 +89,4 @@ exports = { mixin, deepMerge, values, -} \ No newline at end of file +}; From cd4831537eea7e0547dd68f7626303a2012d0d8e Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 17:16:17 -0700 Subject: [PATCH 05/19] Migrate core/utils/deprecation.js to ES6 const/let --- core/utils/deprecation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/deprecation.js b/core/utils/deprecation.js index 4c948f22b..b849c2a1a 100644 --- a/core/utils/deprecation.js +++ b/core/utils/deprecation.js @@ -31,8 +31,8 @@ goog.provide('Blockly.utils.deprecation'); */ Blockly.utils.deprecation.warn = function( name, deprecationDate, deletionDate, opt_use) { - var msg = name + ' was deprecated on ' + deprecationDate + - ' and will be deleted on ' + deletionDate + '.'; + let msg = name + ' was deprecated on ' + deprecationDate + + ' and will be deleted on ' + deletionDate + '.'; if (opt_use) { msg += '\nUse ' + opt_use + ' instead.'; } From 2bf717019fc555fb9f6d6a713460929b18b105e5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 18:12:10 -0700 Subject: [PATCH 06/19] Migrate core/utils/deprecation.js to goog.module --- core/utils/deprecation.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/utils/deprecation.js b/core/utils/deprecation.js index b849c2a1a..a361f563d 100644 --- a/core/utils/deprecation.js +++ b/core/utils/deprecation.js @@ -15,7 +15,8 @@ * @name Blockly.utils.deprecation * @namespace */ -goog.provide('Blockly.utils.deprecation'); +goog.module('Blockly.utils.deprecation'); +goog.module.declareLegacyNamespace(); /** @@ -29,7 +30,7 @@ goog.provide('Blockly.utils.deprecation'); * if any. * @package */ -Blockly.utils.deprecation.warn = function( +const warn = function( name, deprecationDate, deletionDate, opt_use) { let msg = name + ' was deprecated on ' + deprecationDate + ' and will be deleted on ' + deletionDate + '.'; @@ -38,3 +39,5 @@ Blockly.utils.deprecation.warn = function( } console.warn(msg); }; + +exports = {warn}; diff --git a/tests/deps.js b/tests/deps.js index 45860bd0c..daed787d5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -172,7 +172,7 @@ goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Bl goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); -goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], []); +goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); From 819a0f1596c66faa0cf5bcc88fe912d8c42b0422 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 18:12:13 -0700 Subject: [PATCH 07/19] clang-format core/utils/deprecation.js --- core/utils/deprecation.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/utils/deprecation.js b/core/utils/deprecation.js index a361f563d..ad798b1ab 100644 --- a/core/utils/deprecation.js +++ b/core/utils/deprecation.js @@ -30,8 +30,7 @@ goog.module.declareLegacyNamespace(); * if any. * @package */ -const warn = function( - name, deprecationDate, deletionDate, opt_use) { +const warn = function(name, deprecationDate, deletionDate, opt_use) { let msg = name + ' was deprecated on ' + deprecationDate + ' and will be deleted on ' + deletionDate + '.'; if (opt_use) { From 08911510d2c18ad66d41007727abc1a688d93239 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 14 Jul 2021 13:23:57 -0700 Subject: [PATCH 08/19] Migrate core/utils/idgenerator.js to goog.module --- core/utils/idgenerator.js | 11 +++++++---- tests/deps.js | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/utils/idgenerator.js b/core/utils/idgenerator.js index 347b71d02..6ad7bcf55 100644 --- a/core/utils/idgenerator.js +++ b/core/utils/idgenerator.js @@ -16,7 +16,8 @@ * @name Blockly.utils.IdGenerator * @namespace */ -goog.provide('Blockly.utils.IdGenerator'); +goog.module('Blockly.utils.IdGenerator'); +goog.module.declareLegacyNamespace(); /** @@ -24,7 +25,7 @@ goog.provide('Blockly.utils.IdGenerator'); * @type {number} * @private */ -Blockly.utils.IdGenerator.nextId_ = 0; +let nextId = 0; /** * Gets the next unique ID. @@ -32,6 +33,8 @@ Blockly.utils.IdGenerator.nextId_ = 0; * Use only ASCII letters, digits, '_', '-' and '.' * @return {string} The next unique identifier. */ -Blockly.utils.IdGenerator.getNextUniqueId = function() { - return 'blockly-' + (Blockly.utils.IdGenerator.nextId_++).toString(36); +const getNextUniqueId = function() { + return 'blockly-' + (nextId++).toString(36); }; + +exports = {getNextUniqueId}; diff --git a/tests/deps.js b/tests/deps.js index 45860bd0c..d0f01aef3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -4,6 +4,7 @@ goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Co goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); +goog.addDependency('../../blocks/test_blocks.js', ['Blockly.TestBlocks'], ['Blockly', 'Blockly.Blocks'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -175,7 +176,7 @@ goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate' goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], []); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); -goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); +goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); From 72a07613120361d3ecc9425dd2e5127f7bd40016 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:43:15 -0700 Subject: [PATCH 09/19] Migrate core/utils/svg_paths.js to goog.module --- core/utils/svg_paths.js | 30 +++++++++++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/core/utils/svg_paths.js b/core/utils/svg_paths.js index e123dca28..d380d45f6 100644 --- a/core/utils/svg_paths.js +++ b/core/utils/svg_paths.js @@ -15,7 +15,8 @@ * @name Blockly.utils.svgPaths * @namespace */ -goog.provide('Blockly.utils.svgPaths'); +goog.module('Blockly.utils.svgPaths'); +goog.module.declareLegacyNamespace(); /** @@ -28,7 +29,7 @@ goog.provide('Blockly.utils.svgPaths'); * @return {string} A string of the format ' x,y ' * @public */ -Blockly.utils.svgPaths.point = function(x, y) { +const point = function(x, y) { return ' ' + x + ',' + y + ' '; }; @@ -45,7 +46,7 @@ Blockly.utils.svgPaths.point = function(x, y) { * documentation for exact format. * @public */ -Blockly.utils.svgPaths.curve = function(command, points) { +const curve = function(command, points) { return ' ' + command + points.join(''); }; @@ -59,7 +60,7 @@ Blockly.utils.svgPaths.curve = function(command, points) { * @return {string} A string of the format ' M x,y ' * @public */ -Blockly.utils.svgPaths.moveTo = function(x, y) { +const moveTo = function(x, y) { return ' M ' + x + ',' + y + ' '; }; @@ -73,7 +74,7 @@ Blockly.utils.svgPaths.moveTo = function(x, y) { * @return {string} A string of the format ' m dx,dy ' * @public */ -Blockly.utils.svgPaths.moveBy = function(dx, dy) { +const moveBy = function(dx, dy) { return ' m ' + dx + ',' + dy + ' '; }; @@ -87,7 +88,7 @@ Blockly.utils.svgPaths.moveBy = function(dx, dy) { * @return {string} A string of the format ' l dx,dy ' * @public */ -Blockly.utils.svgPaths.lineTo = function(dx, dy) { +const lineTo = function(dx, dy) { return ' l ' + dx + ',' + dy + ' '; }; @@ -102,7 +103,7 @@ Blockly.utils.svgPaths.lineTo = function(dx, dy) { * @return {string} A string of the format ' l (dx,dy)+ ' * @public */ -Blockly.utils.svgPaths.line = function(points) { +const line = function(points) { return ' l' + points.join(''); }; @@ -119,7 +120,7 @@ Blockly.utils.svgPaths.line = function(points) { * @return {string} A string of the format ' command val ' * @public */ -Blockly.utils.svgPaths.lineOnAxis = function(command, val) { +const lineOnAxis = function(command, val) { return ' ' + command + ' ' + val + ' '; }; @@ -137,6 +138,17 @@ Blockly.utils.svgPaths.lineOnAxis = function(command, val) { * @return {string} A string of the format 'command radius radius flags point' * @public */ -Blockly.utils.svgPaths.arc = function(command, flags, radius, point) { +const arc = function(command, flags, radius, point) { return command + ' ' + radius + ' ' + radius + ' ' + flags + point; }; + +exports = { + point, + curve, + moveTo, + moveBy, + lineTo, + line, + lineOnAxis, + arc, +}; diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..1c324ff68 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -185,7 +185,7 @@ goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); -goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); +goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); From 916b49a2e5d4a757dbf4d6504af1713edfee32ff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:44:17 -0700 Subject: [PATCH 10/19] clang-format core/utils/svg_paths.js --- core/utils/svg_paths.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/utils/svg_paths.js b/core/utils/svg_paths.js index d380d45f6..02602e4ac 100644 --- a/core/utils/svg_paths.js +++ b/core/utils/svg_paths.js @@ -39,9 +39,9 @@ const point = function(x, y) { * These coordinates are unitless and hence in the user coordinate system. * @param {string} command The command to use. * Should be one of: c, C, s, S, q, Q. - * @param {!Array} points An array containing all of the points to pass to the - * curve command, in order. The points are represented as strings of the - * format ' x, y '. + * @param {!Array} points An array containing all of the points to pass + * to the curve command, in order. The points are represented as strings of + * the format ' x, y '. * @return {string} A string defining one or more Bezier curves. See the MDN * documentation for exact format. * @public From 5fbf5fe40d97e4ad7b40b0c3c848e4c43478069d Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 10:39:37 -0700 Subject: [PATCH 11/19] Migrate core/utils/math.js to ES6 const/let --- core/utils/math.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/utils/math.js b/core/utils/math.js index 516972579..e85b808e7 100644 --- a/core/utils/math.js +++ b/core/utils/math.js @@ -48,7 +48,7 @@ Blockly.utils.math.toDegrees = function(angleRadians) { */ Blockly.utils.math.clamp = function(lowerBound, number, upperBound) { if (upperBound < lowerBound) { - var temp = upperBound; + const temp = upperBound; upperBound = lowerBound; lowerBound = temp; } From 06cbde1dba0f3dbf11ac9e8d63b5d40abdc9d2d4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 10:45:45 -0700 Subject: [PATCH 12/19] Migrate core/utils/math.js to goog.module --- core/utils/math.js | 11 +++++++---- tests/deps.js | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/utils/math.js b/core/utils/math.js index e85b808e7..2bc28eefe 100644 --- a/core/utils/math.js +++ b/core/utils/math.js @@ -16,7 +16,8 @@ * @name Blockly.utils.math * @namespace */ -goog.provide('Blockly.utils.math'); +goog.module('Blockly.utils.math'); +goog.module.declareLegacyNamespace(); /** @@ -25,7 +26,7 @@ goog.provide('Blockly.utils.math'); * @param {number} angleDegrees Angle in degrees. * @return {number} Angle in radians. */ -Blockly.utils.math.toRadians = function(angleDegrees) { +const toRadians = function(angleDegrees) { return angleDegrees * Math.PI / 180; }; @@ -35,7 +36,7 @@ Blockly.utils.math.toRadians = function(angleDegrees) { * @param {number} angleRadians Angle in radians. * @return {number} Angle in degrees. */ -Blockly.utils.math.toDegrees = function(angleRadians) { +const toDegrees = function(angleRadians) { return angleRadians * 180 / Math.PI; }; @@ -46,7 +47,7 @@ Blockly.utils.math.toDegrees = function(angleRadians) { * @param {number} upperBound The desired upper bound. * @return {number} The clamped number. */ -Blockly.utils.math.clamp = function(lowerBound, number, upperBound) { +const clamp = function(lowerBound, number, upperBound) { if (upperBound < lowerBound) { const temp = upperBound; upperBound = lowerBound; @@ -54,3 +55,5 @@ Blockly.utils.math.clamp = function(lowerBound, number, upperBound) { } return Math.max(lowerBound, Math.min(number, upperBound)); }; + +exports = {toRadians, toDegrees, clamp}; diff --git a/tests/deps.js b/tests/deps.js index f24feabaa..ecc86147d 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -4,7 +4,6 @@ goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Co goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); -goog.addDependency('../../blocks/test_blocks.js', ['Blockly.TestBlocks'], ['Blockly', 'Blockly.Blocks'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -178,7 +177,7 @@ goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.u goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); +goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); From 7cc85d9c4a172ce4efba910e8ad4ca848542ce8f Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 15:02:20 -0700 Subject: [PATCH 13/19] clang-format core/utils/math.js --- core/utils/math.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/utils/math.js b/core/utils/math.js index 2bc28eefe..dade91c21 100644 --- a/core/utils/math.js +++ b/core/utils/math.js @@ -56,4 +56,8 @@ const clamp = function(lowerBound, number, upperBound) { return Math.max(lowerBound, Math.min(number, upperBound)); }; -exports = {toRadians, toDegrees, clamp}; +exports = { + toRadians, + toDegrees, + clamp +}; From 38324a1f637d20f87ca9090e0e1172bc2f4fbaf7 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 14 Jul 2021 15:59:30 -0700 Subject: [PATCH 14/19] Updates eslint rules to work while converting to goog.module (#5063) --- .eslintrc.json | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9d74291da..28766db11 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,29 +2,6 @@ "rules": { "curly": ["error"], "eol-last": ["error"], - // Blockly/Google use 2-space indents. - // Blockly/Google uses +4 space indents for line continuations. - // Ignore default rules for ternary expressions. - "indent": [ - "error", 2, - { - "SwitchCase": 1, - "MemberExpression": 2, - "ObjectExpression": 1, - "FunctionDeclaration": { - "body": 1, - "parameters": 2 - }, - "FunctionExpression": { - "body": 1, - "parameters": 2 - }, - "CallExpression": { - "arguments": 2 - }, - "ignoredNodes": ["ConditionalExpression"] - } - ], "keyword-spacing": ["error"], "linebreak-style": ["error", "unix"], "max-len": [ @@ -39,7 +16,7 @@ ], "no-trailing-spaces": ["error", { "skipBlankLines": true }], "no-unused-vars": [ - "error", + "warn", { "args": "after-used", // Ignore vars starting with an underscore. @@ -48,7 +25,6 @@ "argsIgnorePattern": "^_" } ], - "no-use-before-define": ["error"], // Blockly uses for exporting symbols. no-self-assign added in eslint 5. "no-self-assign": ["off"], // Blockly uses single quotes except for JSON blobs, which must use double quotes. From 466a0db8099d34dba282c8c2d55549753ca6a610 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 13:56:18 -0700 Subject: [PATCH 15/19] Migrate core/utils/rect.js to goog.module --- core/utils/rect.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/utils/rect.js b/core/utils/rect.js index 128ec4eae..318cf1d0d 100644 --- a/core/utils/rect.js +++ b/core/utils/rect.js @@ -16,7 +16,8 @@ * @name Blockly.utils.Rect * @namespace */ -goog.provide('Blockly.utils.Rect'); +goog.module('Blockly.utils.Rect'); +goog.module.declareLegacyNamespace(); /** @@ -28,7 +29,7 @@ goog.provide('Blockly.utils.Rect'); * @struct * @constructor */ -Blockly.utils.Rect = function(top, bottom, left, right) { +const Rect = function(top, bottom, left, right) { /** @type {number} */ this.top = top; @@ -49,7 +50,7 @@ Blockly.utils.Rect = function(top, bottom, left, right) { * @param {number} y The y coordinate to test for containment. * @return {boolean} Whether this rectangle contains given coordinate. */ -Blockly.utils.Rect.prototype.contains = function(x, y) { +Rect.prototype.contains = function(x, y) { return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom; }; @@ -60,7 +61,9 @@ Blockly.utils.Rect.prototype.contains = function(x, y) { * intersection with. * @return {boolean} Whether this rectangle intersects the provided rectangle. */ -Blockly.utils.Rect.prototype.intersects = function(other) { +Rect.prototype.intersects = function(other) { return !(this.left > other.right || this.right < other.left || this.top > other.bottom || this.bottom < other.top); }; + +exports = Rect; diff --git a/tests/deps.js b/tests/deps.js index 4e222cf85..b98f68ecd 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -180,7 +180,7 @@ goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); +goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); From de2cff80fdec4a262048bbb401b95d6e90163e80 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 16:11:11 -0700 Subject: [PATCH 16/19] clang-format core/utils/rect.js --- core/utils/rect.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/utils/rect.js b/core/utils/rect.js index 318cf1d0d..85ade5388 100644 --- a/core/utils/rect.js +++ b/core/utils/rect.js @@ -62,7 +62,8 @@ Rect.prototype.contains = function(x, y) { * @return {boolean} Whether this rectangle intersects the provided rectangle. */ Rect.prototype.intersects = function(other) { - return !(this.left > other.right || this.right < other.left || + return !( + this.left > other.right || this.right < other.left || this.top > other.bottom || this.bottom < other.top); }; From 426c741e90f9134e013f5b37742c8dde6d6b1d11 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 17:03:33 -0700 Subject: [PATCH 17/19] Migrate core/utils/colour.js to ES6 const/let --- core/utils/colour.js | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/core/utils/colour.js b/core/utils/colour.js index b64b81eb5..12c9a9998 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -32,7 +32,7 @@ goog.provide('Blockly.utils.colour'); */ Blockly.utils.colour.parse = function(str) { str = String(str).toLowerCase().trim(); - var hex = Blockly.utils.colour.names[str]; + let hex = Blockly.utils.colour.names[str]; if (hex) { // e.g. 'red' return hex; @@ -47,12 +47,12 @@ Blockly.utils.colour.parse = function(str) { // e.g. '#0f8' return ['#', hex[1], hex[1], hex[2], hex[2], hex[3], hex[3]].join(''); } - var rgb = str.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/); + const rgb = str.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/); if (rgb) { // e.g. 'rgb(0, 128, 255)' - var r = Number(rgb[1]); - var g = Number(rgb[2]); - var b = Number(rgb[3]); + const r = Number(rgb[1]); + const g = Number(rgb[2]); + const b = Number(rgb[3]); if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256) { return Blockly.utils.colour.rgbToHex(r, g, b); } @@ -68,7 +68,7 @@ Blockly.utils.colour.parse = function(str) { * @return {string} Hex representation of the colour. */ Blockly.utils.colour.rgbToHex = function(r, g, b) { - var rgb = (r << 16) | (g << 8) | b; + const rgb = (r << 16) | (g << 8) | b; if (r < 0x10) { return '#' + (0x1000000 | rgb).toString(16).substr(1); } @@ -82,15 +82,15 @@ Blockly.utils.colour.rgbToHex = function(r, g, b) { * @return {!Array} RGB representation of the colour. */ Blockly.utils.colour.hexToRgb = function(colour) { - var hex = Blockly.utils.colour.parse(colour); + const hex = Blockly.utils.colour.parse(colour); if (!hex) { return [0, 0, 0]; } - var rgb = parseInt(hex.substr(1), 16); - var r = rgb >> 16; - var g = (rgb >> 8) & 255; - var b = rgb & 255; + const rgb = parseInt(hex.substr(1), 16); + const r = rgb >> 16; + const g = (rgb >> 8) & 255; + const b = rgb & 255; return [r, g, b]; }; @@ -103,19 +103,19 @@ Blockly.utils.colour.hexToRgb = function(colour) { * @return {string} Hex representation of the colour. */ Blockly.utils.colour.hsvToHex = function(h, s, v) { - var red = 0; - var green = 0; - var blue = 0; + let red = 0; + let green = 0; + let blue = 0; if (s == 0) { red = v; green = v; blue = v; } else { - var sextant = Math.floor(h / 60); - var remainder = (h / 60) - sextant; - var val1 = v * (1 - s); - var val2 = v * (1 - (s * remainder)); - var val3 = v * (1 - (s * (1 - remainder))); + const sextant = Math.floor(h / 60); + const remainder = (h / 60) - sextant; + const val1 = v * (1 - s); + const val2 = v * (1 - (s * remainder)); + const val3 = v * (1 - (s * (1 - remainder))); switch (sextant) { case 1: red = val2; @@ -164,19 +164,19 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { * @return {?string} Combined colour represented in hex. */ Blockly.utils.colour.blend = function(colour1, colour2, factor) { - var hex1 = Blockly.utils.colour.parse(colour1); + const hex1 = Blockly.utils.colour.parse(colour1); if (!hex1) { return null; } - var hex2 = Blockly.utils.colour.parse(colour2); + const 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])); + const rgb1 = Blockly.utils.colour.hexToRgb(hex1); + const rgb2 = Blockly.utils.colour.hexToRgb(hex2); + const r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0])); + const g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1])); + const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); return Blockly.utils.colour.rgbToHex(r, g, b); }; From 8abfa3d888f81136d6cc337a154aea7e0a7b0477 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:53:16 -0700 Subject: [PATCH 18/19] Migrate core/utils/colour.js to goog.module --- core/utils/colour.js | 35 +++++++++++++++++++---------------- tests/deps.js | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/core/utils/colour.js b/core/utils/colour.js index 12c9a9998..dffd193f3 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -16,7 +16,8 @@ * @name Blockly.utils.colour * @namespace */ -goog.provide('Blockly.utils.colour'); +goog.module('Blockly.utils.colour'); +goog.module.declareLegacyNamespace(); /** @@ -30,9 +31,9 @@ goog.provide('Blockly.utils.colour'); * @return {?string} A string containing a hex representation of the colour, * or null if can't be parsed. */ -Blockly.utils.colour.parse = function(str) { +const parse = function(str) { str = String(str).toLowerCase().trim(); - let hex = Blockly.utils.colour.names[str]; + let hex = names[str]; if (hex) { // e.g. 'red' return hex; @@ -54,7 +55,7 @@ Blockly.utils.colour.parse = function(str) { const g = Number(rgb[2]); const b = Number(rgb[3]); if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256) { - return Blockly.utils.colour.rgbToHex(r, g, b); + return rgbToHex(r, g, b); } } return null; @@ -67,7 +68,7 @@ Blockly.utils.colour.parse = function(str) { * @param {number} b Amount of blue, int between 0 and 255. * @return {string} Hex representation of the colour. */ -Blockly.utils.colour.rgbToHex = function(r, g, b) { +const rgbToHex = function(r, g, b) { const rgb = (r << 16) | (g << 8) | b; if (r < 0x10) { return '#' + (0x1000000 | rgb).toString(16).substr(1); @@ -81,8 +82,8 @@ Blockly.utils.colour.rgbToHex = function(r, g, b) { * colour format ('#ff0000', 'red', '0xff000', etc). * @return {!Array} RGB representation of the colour. */ -Blockly.utils.colour.hexToRgb = function(colour) { - const hex = Blockly.utils.colour.parse(colour); +const hexToRgb = function(colour) { + const hex = parse(colour); if (!hex) { return [0, 0, 0]; } @@ -102,7 +103,7 @@ Blockly.utils.colour.hexToRgb = function(colour) { * @param {number} v Brightness in [0, 255]. * @return {string} Hex representation of the colour. */ -Blockly.utils.colour.hsvToHex = function(h, s, v) { +const hsvToHex = function(h, s, v) { let red = 0; let green = 0; let blue = 0; @@ -150,7 +151,7 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { break; } } - return Blockly.utils.colour.rgbToHex( + return rgbToHex( Math.floor(red), Math.floor(green), Math.floor(blue)); }; @@ -163,21 +164,21 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { * Values should be in the range [0, 1]. * @return {?string} Combined colour represented in hex. */ -Blockly.utils.colour.blend = function(colour1, colour2, factor) { - const hex1 = Blockly.utils.colour.parse(colour1); +const blend = function(colour1, colour2, factor) { + const hex1 = parse(colour1); if (!hex1) { return null; } - const hex2 = Blockly.utils.colour.parse(colour2); + const hex2 = parse(colour2); if (!hex2) { return null; } - const rgb1 = Blockly.utils.colour.hexToRgb(hex1); - const rgb2 = Blockly.utils.colour.hexToRgb(hex2); + const rgb1 = hexToRgb(hex1); + const rgb2 = hexToRgb(hex2); const r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0])); const g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1])); const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); - return Blockly.utils.colour.rgbToHex(r, g, b); + return rgbToHex(r, g, b); }; /** @@ -188,7 +189,7 @@ Blockly.utils.colour.blend = function(colour1, colour2, factor) { * * @type {!Object} */ -Blockly.utils.colour.names = { +const names = { 'aqua': '#00ffff', 'black': '#000000', 'blue': '#0000ff', @@ -206,3 +207,5 @@ Blockly.utils.colour.names = { 'white': '#ffffff', 'yellow': '#ffff00' }; + +exports = {parse, rgbToHex, hexToRgb, hsvToHex, blend, names}; diff --git a/tests/deps.js b/tests/deps.js index b98f68ecd..e83f61c67 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -170,7 +170,7 @@ goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Bl goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); -goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); +goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); From f63bf29b7689b0ed92cfa2fb70f1be9b79fda2b8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:53:21 -0700 Subject: [PATCH 19/19] clang-format core/utils/colour.js --- core/utils/colour.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/utils/colour.js b/core/utils/colour.js index dffd193f3..7b2c978f4 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -151,8 +151,7 @@ const hsvToHex = function(h, s, v) { break; } } - return rgbToHex( - Math.floor(red), Math.floor(green), Math.floor(blue)); + return rgbToHex(Math.floor(red), Math.floor(green), Math.floor(blue)); }; /** @@ -208,4 +207,11 @@ const names = { 'yellow': '#ffff00' }; -exports = {parse, rgbToHex, hexToRgb, hsvToHex, blend, names}; +exports = { + parse, + rgbToHex, + hexToRgb, + hsvToHex, + blend, + names +};