From f1a41023d9a21ccd121c10aea22eb897a9a95925 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:27:35 -0700 Subject: [PATCH 1/4] Migrate core/field_registry.js to ES6 const/let --- core/field_registry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_registry.js b/core/field_registry.js index 7f431ff7d..463308d3e 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -54,7 +54,7 @@ Blockly.fieldRegistry.unregister = function(type) { * @package */ Blockly.fieldRegistry.fromJson = function(options) { - var fieldObject = /** @type {?Blockly.IRegistrableField} */ ( + const fieldObject = /** @type {?Blockly.IRegistrableField} */ ( Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type'])); if (!fieldObject) { console.warn('Blockly could not create a field of type ' + options['type'] + From 063dc8b804af6caa117afbe361b5cfde7ec6fd22 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:30:54 -0700 Subject: [PATCH 2/4] Migrate core/field_registry.js to goog.module --- core/field_registry.js | 14 +++++++++----- tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/field_registry.js b/core/field_registry.js index 463308d3e..f1c342579 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.fieldRegistry'); +goog.module('Blockly.fieldRegistry'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.registry'); @@ -31,17 +32,19 @@ goog.requireType('Blockly.IRegistrableField'); * registered, or the fieldClass is not an object containing a fromJson * function. */ -Blockly.fieldRegistry.register = function(type, fieldClass) { +const register = function(type, fieldClass) { Blockly.registry.register(Blockly.registry.Type.FIELD, type, fieldClass); }; +exports.register = register; /** * Unregisters the field registered with the given type. * @param {string} type The field type name as used in the JSON definition. */ -Blockly.fieldRegistry.unregister = function(type) { +const unregister = function(type) { Blockly.registry.unregister(Blockly.registry.Type.FIELD, type); }; +exports.unregister = unregister; /** * Construct a Field from a JSON arg object. @@ -51,9 +54,8 @@ Blockly.fieldRegistry.unregister = function(type) { * to the field type. * @return {?Blockly.Field} The new field instance or null if a field wasn't * found with the given type name - * @package */ -Blockly.fieldRegistry.fromJson = function(options) { +const fromJson = function(options) { const fieldObject = /** @type {?Blockly.IRegistrableField} */ ( Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type'])); if (!fieldObject) { @@ -65,3 +67,5 @@ Blockly.fieldRegistry.fromJson = function(options) { } return fieldObject.fromJson(options); }; +/** @package */ +exports.fromJson = fromJson; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..2cb4d384f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -58,7 +58,7 @@ goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockl goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); +goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); From 222b23480253e7a35e0b426baa2a9fa07b966ed2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:34:55 -0700 Subject: [PATCH 3/4] Migrate core/field_registry.js to named requires --- core/field_registry.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/core/field_registry.js b/core/field_registry.js index f1c342579..1ae36d903 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -15,25 +15,26 @@ goog.module('Blockly.fieldRegistry'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.registry'); - -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IRegistrableField'); +/* eslint-disable-next-line no-unused-vars */ +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const IRegistrableField = goog.requireType('Blockly.IRegistrableField'); +const registry = goog.require('Blockly.registry'); /** * Registers a field type. - * Blockly.fieldRegistry.fromJson uses this registry to + * fieldRegistry.fromJson uses this registry to * find the appropriate field type. * @param {string} type The field type name as used in the JSON definition. - * @param {!Blockly.IRegistrableField} fieldClass The field class containing a + * @param {!IRegistrableField} fieldClass The field class containing a * fromJson function that can construct an instance of the field. * @throws {Error} if the type name is empty, the field is already * registered, or the fieldClass is not an object containing a fromJson * function. */ const register = function(type, fieldClass) { - Blockly.registry.register(Blockly.registry.Type.FIELD, type, fieldClass); + registry.register(registry.Type.FIELD, type, fieldClass); }; exports.register = register; @@ -42,22 +43,22 @@ exports.register = register; * @param {string} type The field type name as used in the JSON definition. */ const unregister = function(type) { - Blockly.registry.unregister(Blockly.registry.Type.FIELD, type); + registry.unregister(registry.Type.FIELD, type); }; exports.unregister = unregister; /** * Construct a Field from a JSON arg object. * Finds the appropriate registered field by the type name as registered using - * Blockly.fieldRegistry.register. + * fieldRegistry.register. * @param {!Object} options A JSON object with a type and options specific * to the field type. - * @return {?Blockly.Field} The new field instance or null if a field wasn't + * @return {?Field} The new field instance or null if a field wasn't * found with the given type name */ const fromJson = function(options) { - const fieldObject = /** @type {?Blockly.IRegistrableField} */ ( - Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type'])); + const fieldObject = /** @type {?IRegistrableField} */ ( + registry.getObject(registry.Type.FIELD, options['type'])); if (!fieldObject) { console.warn('Blockly could not create a field of type ' + options['type'] + '. The field is probably not being registered. This could be because' + From 223ec1dd6c717dc12ccf1e9d78f6a4eb783f93e9 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:35:25 -0700 Subject: [PATCH 4/4] clang-format core/field_registry.js --- core/field_registry.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/field_registry.js b/core/field_registry.js index 1ae36d903..97c149346 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -58,12 +58,13 @@ exports.unregister = unregister; */ const fromJson = function(options) { const fieldObject = /** @type {?IRegistrableField} */ ( - registry.getObject(registry.Type.FIELD, options['type'])); + registry.getObject(registry.Type.FIELD, options['type'])); if (!fieldObject) { - console.warn('Blockly could not create a field of type ' + options['type'] + - '. The field is probably not being registered. This could be because' + - ' the file is not loaded, the field does not register itself (Issue' + - ' #1584), or the registration is not being reached.'); + console.warn( + 'Blockly could not create a field of type ' + options['type'] + + '. The field is probably not being registered. This could be because' + + ' the file is not loaded, the field does not register itself (Issue' + + ' #1584), or the registration is not being reached.'); return null; } return fieldObject.fromJson(options);