From 78b8e2fa85aae38ca3c01ef7b194863a21c9071e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 13 Jul 2021 14:42:56 -0700 Subject: [PATCH 1/3] 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 2/3] 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 b92fba1a5a934d051be8e0e1fb9b4b8497c7ecf5 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 10:55:10 -0700 Subject: [PATCH 3/3] 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 +};