From b52c0179cb107108ea54434834dd28f59799918e Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Fri, 3 Dec 2021 02:45:47 +0000 Subject: [PATCH] chore: Fix inadvertent block migration inconsistencies (#5780) * chore: Fix inadvertent block migration inconsistencies - Reinstate `goog.require`s-for-side-effects that were inadvertently removed. - Always use a destructuring import for `defineBlocksWithJsonArray`. - Consistently use `CONSTANT_CASE` names for block-common objects. (We could alternatively always use `camelCase` names, but since all the `MIXIN`s and `EXTENSIONS` remain all-uppercase this seems the more consistent.) * chore: Fix import ordering --- blocks/colour.js | 2 ++ blocks/lists.js | 2 ++ blocks/logic.js | 4 ++-- blocks/math.js | 8 ++++---- blocks/procedures.js | 12 ++++++------ tests/deps.js | 4 ++-- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/blocks/colour.js b/blocks/colour.js index c25b7fb85..c2a8b6b4b 100644 --- a/blocks/colour.js +++ b/blocks/colour.js @@ -12,6 +12,8 @@ goog.module('Blockly.blocks.colour'); const {defineBlocksWithJsonArray} = goog.require('Blockly.common'); +/** @suppress {extraRequire} */ +goog.require('Blockly.FieldColour'); defineBlocksWithJsonArray([ diff --git a/blocks/lists.js b/blocks/lists.js index 72721c211..80400536d 100644 --- a/blocks/lists.js +++ b/blocks/lists.js @@ -24,6 +24,8 @@ const {Mutator} = goog.require('Blockly.Mutator'); /* eslint-disable-next-line no-unused-vars */ const {Workspace} = goog.requireType('Blockly.Workspace'); const {defineBlocksWithJsonArray} = goog.require('Blockly.common'); +/** @suppress {extraRequire} */ +goog.require('Blockly.FieldDropdown'); defineBlocksWithJsonArray([ diff --git a/blocks/logic.js b/blocks/logic.js index a7afb8140..8a79d7f94 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -16,7 +16,6 @@ goog.module('Blockly.blocks.logic'); const AbstractEvent = goog.requireType('Blockly.Events.Abstract'); const Events = goog.require('Blockly.Events'); const Extensions = goog.require('Blockly.Extensions'); -const common = goog.require('Blockly.common'); const xmlUtils = goog.require('Blockly.utils.xml'); /* eslint-disable-next-line no-unused-vars */ const {Block} = goog.requireType('Blockly.Block'); @@ -26,13 +25,14 @@ const {Mutator} = goog.require('Blockly.Mutator'); const {RenderedConnection} = goog.requireType('Blockly.RenderedConnection'); /* eslint-disable-next-line no-unused-vars */ const {Workspace} = goog.requireType('Blockly.Workspace'); +const {defineBlocksWithJsonArray} = goog.require('Blockly.common'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldDropdown'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldLabel'); -common.defineBlocksWithJsonArray([ +defineBlocksWithJsonArray([ // Block for boolean data type: true and false. { 'type': 'logic_boolean', diff --git a/blocks/math.js b/blocks/math.js index d4c798479..003ff5bdc 100644 --- a/blocks/math.js +++ b/blocks/math.js @@ -13,13 +13,13 @@ goog.module('Blockly.blocks.math'); const Extensions = goog.require('Blockly.Extensions'); -/* eslint-disable-next-line no-unused-vars */ -const xmlUtils = goog.require('Blockly.utils.xml'); -/* eslint-disable-next-line no-unused-vars */ -const {Block} = goog.requireType('Blockly.Block'); // N.B.: Blockly.FieldDropdown needed for type AND side-effects. /* eslint-disable-next-line no-unused-vars */ const FieldDropdown = goog.require('Blockly.FieldDropdown'); +const xmlUtils = goog.require('Blockly.utils.xml'); +/* eslint-disable-next-line no-unused-vars */ +const {Block} = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ const {defineBlocksWithJsonArray} = goog.require('Blockly.common'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldLabel'); diff --git a/blocks/procedures.js b/blocks/procedures.js index fc08337a9..c41eb92db 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -46,7 +46,7 @@ goog.require('Blockly.Warning'); * Common properties for the procedure_defnoreturn and * procedure_defreturn blocks. */ -const procedureDef = { +const PROCEDURE_DEF_COMMON = { /** * Add or remove the statement block from this function definition. * @param {boolean} hasStatements True if a statement block is needed. @@ -438,7 +438,7 @@ const procedureDef = { }; Blocks['procedures_defnoreturn'] = { - ...procedureDef, + ...PROCEDURE_DEF_COMMON, /** * Block for defining a procedure with no return value. * @this {Block} @@ -480,7 +480,7 @@ Blocks['procedures_defnoreturn'] = { }; Blocks['procedures_defreturn'] = { - ...procedureDef, + ...PROCEDURE_DEF_COMMON, /** * Block for defining a procedure with a return value. * @this {Block} @@ -659,7 +659,7 @@ Blocks['procedures_mutatorarg'] = { * Common properties for the procedure_callnoreturn and * procedure_callreturn blocks. */ -const procedureCall = { +const PROCEDURE_CALL_COMMON = { /** * Returns the name of the procedure this block calls. * @return {string} Procedure name. @@ -1034,7 +1034,7 @@ const procedureCall = { }; Blocks['procedures_callnoreturn'] = { - ...procedureCall, + ...PROCEDURE_CALL_COMMON, /** * Block for calling a procedure with no return value. * @this {Block} @@ -1057,7 +1057,7 @@ Blocks['procedures_callnoreturn'] = { }; Blocks['procedures_callreturn'] = { - ...procedureCall, + ...PROCEDURE_CALL_COMMON, /** * Block for calling a procedure with a return value. * @this {Block} diff --git a/tests/deps.js b/tests/deps.js index 1274212cf..62a32fc02 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -1,6 +1,6 @@ goog.addDependency('../../blocks/all.js', ['Blockly.blocks.all'], ['Blockly.blocks.colour', 'Blockly.blocks.lists', 'Blockly.blocks.logic', 'Blockly.blocks.loops', 'Blockly.blocks.math', 'Blockly.blocks.procedures', 'Blockly.blocks.texts', 'Blockly.blocks.variables', 'Blockly.blocks.variablesDynamic'], {'module': 'goog'}); -goog.addDependency('../../blocks/colour.js', ['Blockly.blocks.colour'], ['Blockly.common'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../blocks/lists.js', ['Blockly.blocks.lists'], ['Blockly.ConnectionType', 'Blockly.FieldDropdown', 'Blockly.Input', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.blocks', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../blocks/colour.js', ['Blockly.blocks.colour'], ['Blockly.FieldColour', 'Blockly.common'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../blocks/lists.js', ['Blockly.blocks.lists'], ['Blockly.ConnectionType', 'Blockly.FieldDropdown', 'Blockly.FieldDropdown', 'Blockly.Input', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.blocks', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../blocks/logic.js', ['Blockly.blocks.logic'], ['Blockly.Events', 'Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../blocks/loops.js', ['Blockly.blocks.loops'], ['Blockly.ContextMenu', 'Blockly.Events', 'Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Msg', 'Blockly.Variables', 'Blockly.Warning', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../blocks/math.js', ['Blockly.blocks.math'], ['Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});