Skip to content

Commit

Permalink
refactor: Migrate blocks/loops.js to goog.module syntax (#5755)
Browse files Browse the repository at this point in the history
* refactor: Turn .getSurroundLoop into a (Block) method

  This considerably simplifies the code in the genrators, obviating
  the need for generators to import Blockly.Constants.Loops, and
  allowing the compiler to remove blocks/loops.js from the first
  (Blockly) chunk of the compilation.

  (The latter could and should have been arranged by making the
  generator chunks depend on the blocks chunk, but that is no longer
  necessary.)

* refactor: Migrate blocks/loops.js to goog.module

* refactor: Migrate blocks/loops.js named requires

* chore: clang-format blocks/loops.js
  • Loading branch information
cpcallen authored Nov 30, 2021
1 parent 874bbc1 commit 208d200
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 255 deletions.
393 changes: 204 additions & 189 deletions blocks/loops.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions generators/dart/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ Blockly.Dart['controls_flow_statements'] = function(block) {
xfix += Blockly.Dart.injectId(Blockly.Dart.STATEMENT_SUFFIX, block);
}
if (Blockly.Dart.STATEMENT_PREFIX) {
const loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
const loop = block.getSurroundLoop();
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// of the loop will not get executed if 'continue' is triggered.
Expand Down
4 changes: 1 addition & 3 deletions generators/javascript/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

goog.provide('Blockly.JavaScript.loops');

goog.require('Blockly.Constants.Loops');
goog.require('Blockly.JavaScript');
goog.require('Blockly.utils.string');

Expand Down Expand Up @@ -167,8 +166,7 @@ Blockly.JavaScript['controls_flow_statements'] = function(block) {
block);
}
if (Blockly.JavaScript.STATEMENT_PREFIX) {
const loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
const loop = block.getSurroundLoop();
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// of the loop will not get executed if 'continue' is triggered.
Expand Down
3 changes: 1 addition & 2 deletions generators/lua/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ Blockly.Lua['controls_flow_statements'] = function(block) {
xfix += Blockly.Lua.injectId(Blockly.Lua.STATEMENT_SUFFIX, block);
}
if (Blockly.Lua.STATEMENT_PREFIX) {
const loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
const loop = block.getSurroundLoop();
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// of the loop will not get executed if 'continue' is triggered.
Expand Down
3 changes: 1 addition & 2 deletions generators/php/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ Blockly.PHP['controls_flow_statements'] = function(block) {
xfix += Blockly.PHP.injectId(Blockly.PHP.STATEMENT_SUFFIX, block);
}
if (Blockly.PHP.STATEMENT_PREFIX) {
const loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
const loop = block.getSurroundLoop();
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// of the loop will not get executed if 'continue' is triggered.
Expand Down
3 changes: 1 addition & 2 deletions generators/python/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ Blockly.Python['controls_flow_statements'] = function(block) {
xfix += Blockly.Python.injectId(Blockly.Python.STATEMENT_SUFFIX, block);
}
if (Blockly.Python.STATEMENT_PREFIX) {
const loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
const loop = block.getSurroundLoop();
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// of the loop will not get executed if 'continue' is triggered.
Expand Down
106 changes: 53 additions & 53 deletions scripts/gulpfiles/chunks.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"chunk": [
"requires:259",
"all:9:requires",
"requires:258",
"all:10:requires",
"all1:11:requires",
"all2:11:requires",
"all3:11:requires",
Expand All @@ -11,68 +11,68 @@
"js": [
"./core/serialization/workspaces.js",
"./core/serialization/variables.js",
"./core/inject.js",
"./core/flyout_vertical.js",
"./core/toolbox/toolbox.js",
"./core/interfaces/i_styleable.js",
"./core/flyout_horizontal.js",
"./core/flyout_base.js",
"./core/flyout_metrics_manager.js",
"./core/field_variable.js",
"./core/field_number.js",
"./core/field_multilineinput.js",
"./core/field_label_serializable.js",
"./core/field_colour.js",
"./core/field_checkbox.js",
"./core/field_angle.js",
"./core/toolbox/collapsible_category.js",
"./core/renderers/zelos/measurables/top_row.js",
"./core/renderers/zelos/measurables/inputs.js",
"./core/renderers/zelos/measurables/row_elements.js",
"./core/renderers/zelos/marker_svg.js",
"./core/renderers/zelos/renderer.js",
"./core/field_textinput.js",
"./core/field_image.js",
"./core/renderers/zelos/info.js",
"./core/renderers/zelos/path_object.js",
"./core/renderers/zelos/drawer.js",
"./core/renderers/zelos/constants.js",
"./core/renderers/zelos/measurables/bottom_row.js",
"./core/renderers/zelos/zelos.js",
"./core/renderers/thrasos/renderer.js",
"./core/renderers/thrasos/info.js",
"./core/renderers/thrasos/thrasos.js",
"./core/renderers/minimalist/renderer.js",
"./core/renderers/minimalist/info.js",
"./core/renderers/minimalist/drawer.js",
"./core/renderers/minimalist/constants.js",
"./core/renderers/minimalist/minimalist.js",
"./core/renderers/geras/measurables/statement_input.js",
"./core/contextmenu_items.js",
"./core/shortcut_items.js",
"./core/theme/zelos.js",
"./core/theme/themes.js",
"./core/renderers/geras/constants.js",
"./core/renderers/geras/highlight_constants.js",
"./core/renderers/geras/measurables/inline_input.js",
"./core/renderers/geras/path_object.js",
"./core/renderers/geras/renderer.js",
"./core/renderers/geras/measurables/inline_input.js",
"./core/renderers/geras/measurables/statement_input.js",
"./core/renderers/geras/info.js",
"./core/renderers/geras/highlight_constants.js",
"./core/renderers/geras/highlighter.js",
"./core/renderers/geras/drawer.js",
"./core/renderers/geras/constants.js",
"./core/renderers/geras/geras.js",
"./core/theme/zelos.js",
"./core/theme/themes.js",
"./core/shortcut_items.js",
"./core/contextmenu_items.js",
"./core/menu.js",
"./core/menuitem.js",
"./core/clipboard.js",
"./core/widgetdiv.js",
"./core/contextmenu.js",
"./core/blockly.js",
"./core/renderers/minimalist/constants.js",
"./core/renderers/minimalist/renderer.js",
"./core/renderers/minimalist/info.js",
"./core/renderers/minimalist/drawer.js",
"./core/renderers/minimalist/minimalist.js",
"./core/renderers/thrasos/renderer.js",
"./core/renderers/thrasos/info.js",
"./core/renderers/thrasos/thrasos.js",
"./core/renderers/zelos/measurables/bottom_row.js",
"./core/renderers/zelos/constants.js",
"./core/renderers/zelos/path_object.js",
"./core/field_image.js",
"./core/field_textinput.js",
"./core/renderers/zelos/marker_svg.js",
"./core/renderers/zelos/renderer.js",
"./core/renderers/zelos/measurables/row_elements.js",
"./core/renderers/zelos/measurables/inputs.js",
"./core/renderers/zelos/measurables/top_row.js",
"./core/renderers/zelos/info.js",
"./core/renderers/zelos/drawer.js",
"./core/renderers/zelos/zelos.js",
"./core/toolbox/collapsible_category.js",
"./core/field_angle.js",
"./core/field_checkbox.js",
"./core/field_colour.js",
"./core/field_label_serializable.js",
"./core/field_multilineinput.js",
"./core/flyout_metrics_manager.js",
"./core/flyout_base.js",
"./core/generator.js",
"./core/flyout_horizontal.js",
"./core/interfaces/i_styleable.js",
"./core/toolbox/toolbox.js",
"./core/flyout_vertical.js",
"./core/inject.js",
"./core/blockly.js",
"./core/field_variable.js",
"./core/field_number.js",
"./core/field_dropdown.js",
"./core/events/workspace_events.js",
"./core/events/events_toolbox_item_select.js",
"./core/events/events_ui.js",
"./core/events/events.js",
"./core/widgetdiv.js",
"./core/clipboard.js",
"./core/menuitem.js",
"./core/menu.js",
"./core/contextmenu.js",
"./core/blocks.js",
"./core/utils/useragent.js",
"./core/utils/svg.js",
Expand Down Expand Up @@ -266,13 +266,13 @@
"./core/utils/global.js",
"./core/msg.js",
"./closure/goog/base_minimal.js",
"./blocks/loops.js",
"./core/requires.js",
"./blocks/variables_dynamic.js",
"./blocks/variables.js",
"./blocks/text.js",
"./blocks/procedures.js",
"./blocks/math.js",
"./blocks/loops.js",
"./blocks/logic.js",
"./blocks/lists.js",
"./blocks/colour.js",
Expand Down
4 changes: 2 additions & 2 deletions tests/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 208d200

Please sign in to comment.