From 2aff67498b516c50479c51a5fbda79bd04aa0951 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:49:13 -0700 Subject: [PATCH 1/4] Migrate core/input.js to ES6 const/let --- core/input.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/input.js b/core/input.js index 443bfc83f..315570ed3 100644 --- a/core/input.js +++ b/core/input.js @@ -151,7 +151,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { * @throws {Error} if the field is not present and opt_quiet is false. */ Blockly.Input.prototype.removeField = function(name, opt_quiet) { - for (var i = 0, field; (field = this.fieldRow[i]); i++) { + for (let i = 0, field; (field = this.fieldRow[i]); i++) { if (field.name === name) { field.dispose(); this.fieldRow.splice(i, 1); @@ -189,13 +189,13 @@ Blockly.Input.prototype.setVisible = function(visible) { // Note: Currently there are only unit tests for block.setCollapsed() // because this function is package. If this function goes back to being a // public API tests (lots of tests) should be added. - var renderList = []; + let renderList = []; if (this.visible_ == visible) { return renderList; } this.visible_ = visible; - for (var y = 0, field; (field = this.fieldRow[y]); y++) { + for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.setVisible(visible); } if (this.connection) { @@ -207,7 +207,7 @@ Blockly.Input.prototype.setVisible = function(visible) { } else { this.connection.stopTrackingAll(); } - var child = this.connection.targetBlock(); + const child = this.connection.targetBlock(); if (child) { child.getSvgRoot().style.display = visible ? 'block' : 'none'; } @@ -220,7 +220,7 @@ Blockly.Input.prototype.setVisible = function(visible) { * @package */ Blockly.Input.prototype.markDirty = function() { - for (var y = 0, field; (field = this.fieldRow[y]); y++) { + for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.markDirty(); } }; @@ -285,7 +285,7 @@ Blockly.Input.prototype.init = function() { if (!this.sourceBlock_.workspace.rendered) { return; // Headless blocks don't need fields initialized. } - for (var i = 0; i < this.fieldRow.length; i++) { + for (let i = 0; i < this.fieldRow.length; i++) { this.fieldRow[i].init(); } }; @@ -295,7 +295,7 @@ Blockly.Input.prototype.init = function() { * @suppress {checkTypes} */ Blockly.Input.prototype.dispose = function() { - for (var i = 0, field; (field = this.fieldRow[i]); i++) { + for (let i = 0, field; (field = this.fieldRow[i]); i++) { field.dispose(); } if (this.connection) { From f96c14c0033b27e1a1eef0146fef5f6615283287 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:51:25 -0700 Subject: [PATCH 2/4] Migrate core/input.js to goog.module --- core/input.js | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/core/input.js b/core/input.js index 315570ed3..b9b277fde 100644 --- a/core/input.js +++ b/core/input.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Input'); +goog.module('Blockly.Input'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Connection'); goog.require('Blockly.fieldRegistry'); @@ -33,7 +34,7 @@ goog.requireType('Blockly.RenderedConnection'); * @param {Blockly.Connection} connection Optional connection for this input. * @constructor */ -Blockly.Input = function(type, name, block, connection) { +const Input = function(type, name, block, connection) { if (type != Blockly.inputTypes.DUMMY && !name) { throw Error('Value inputs and statement inputs must have non-empty name.'); } @@ -56,20 +57,20 @@ Blockly.Input = function(type, name, block, connection) { * Alignment of input's fields (left, right or centre). * @type {number} */ -Blockly.Input.prototype.align = Blockly.constants.ALIGN.LEFT; +Input.prototype.align = Blockly.constants.ALIGN.LEFT; /** * Is the input visible? * @type {boolean} * @private */ -Blockly.Input.prototype.visible_ = true; +Input.prototype.visible_ = true; /** * Get the source block for this input. * @return {?Blockly.Block} The source block, or null if there is none. */ -Blockly.Input.prototype.getSourceBlock = function() { +Input.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -79,9 +80,9 @@ Blockly.Input.prototype.getSourceBlock = function() { * @param {string|!Blockly.Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. - * @return {!Blockly.Input} The input being append to (to allow chaining). + * @return {!Input} The input being append to (to allow chaining). */ -Blockly.Input.prototype.appendField = function(field, opt_name) { +Input.prototype.appendField = function(field, opt_name) { this.insertFieldAt(this.fieldRow.length, field, opt_name); return this; }; @@ -95,7 +96,7 @@ Blockly.Input.prototype.appendField = function(field, opt_name) { * this field again. Should be unique to the host block. * @return {number} The index following the last inserted field. */ -Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { +Input.prototype.insertFieldAt = function(index, field, opt_name) { if (index < 0 || index > this.fieldRow.length) { throw Error('index ' + index + ' out of bounds.'); } @@ -150,7 +151,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { * and opt_quiet is true. * @throws {Error} if the field is not present and opt_quiet is false. */ -Blockly.Input.prototype.removeField = function(name, opt_quiet) { +Input.prototype.removeField = function(name, opt_quiet) { for (let i = 0, field; (field = this.fieldRow[i]); i++) { if (field.name === name) { field.dispose(); @@ -174,7 +175,7 @@ Blockly.Input.prototype.removeField = function(name, opt_quiet) { * Gets whether this input is visible or not. * @return {boolean} True if visible. */ -Blockly.Input.prototype.isVisible = function() { +Input.prototype.isVisible = function() { return this.visible_; }; @@ -185,7 +186,7 @@ Blockly.Input.prototype.isVisible = function() { * @return {!Array} List of blocks to render. * @package */ -Blockly.Input.prototype.setVisible = function(visible) { +Input.prototype.setVisible = function(visible) { // Note: Currently there are only unit tests for block.setCollapsed() // because this function is package. If this function goes back to being a // public API tests (lots of tests) should be added. @@ -219,7 +220,7 @@ Blockly.Input.prototype.setVisible = function(visible) { * Mark all fields on this input as dirty. * @package */ -Blockly.Input.prototype.markDirty = function() { +Input.prototype.markDirty = function() { for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.markDirty(); } @@ -229,9 +230,9 @@ Blockly.Input.prototype.markDirty = function() { * Change a connection's compatibility. * @param {string|Array|null} check Compatible value type or * list of value types. Null if all types are compatible. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setCheck = function(check) { +Input.prototype.setCheck = function(check) { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -243,9 +244,9 @@ Blockly.Input.prototype.setCheck = function(check) { * Change the alignment of the connection's field(s). * @param {number} align One of the values of Blockly.constants.ALIGN. * In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setAlign = function(align) { +Input.prototype.setAlign = function(align) { this.align = align; if (this.sourceBlock_.rendered) { this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); @@ -257,9 +258,9 @@ Blockly.Input.prototype.setAlign = function(align) { /** * Changes the connection's shadow block. * @param {?Element} shadow DOM representation of a block or null. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setShadowDom = function(shadow) { +Input.prototype.setShadowDom = function(shadow) { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -271,7 +272,7 @@ Blockly.Input.prototype.setShadowDom = function(shadow) { * Returns the XML representation of the connection's shadow block. * @return {?Element} Shadow DOM representation of a block or null. */ -Blockly.Input.prototype.getShadowDom = function() { +Input.prototype.getShadowDom = function() { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -281,7 +282,7 @@ Blockly.Input.prototype.getShadowDom = function() { /** * Initialize the fields on this input. */ -Blockly.Input.prototype.init = function() { +Input.prototype.init = function() { if (!this.sourceBlock_.workspace.rendered) { return; // Headless blocks don't need fields initialized. } @@ -294,7 +295,7 @@ Blockly.Input.prototype.init = function() { * Sever all links to this input. * @suppress {checkTypes} */ -Blockly.Input.prototype.dispose = function() { +Input.prototype.dispose = function() { for (let i = 0, field; (field = this.fieldRow[i]); i++) { field.dispose(); } @@ -303,3 +304,5 @@ Blockly.Input.prototype.dispose = function() { } this.sourceBlock_ = null; }; + +exports = Input; From f59da974b44dcd4fd1de119ae889815e5e86ca7d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:55:41 -0700 Subject: [PATCH 3/4] Migrate core/input.js to named requires --- core/input.js | 56 +++++++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/core/input.js b/core/input.js index b9b277fde..59c3b8a72 100644 --- a/core/input.js +++ b/core/input.js @@ -13,29 +13,33 @@ goog.module('Blockly.Input'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Connection'); -goog.require('Blockly.fieldRegistry'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.require('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const constants = goog.require('Blockly.constants'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const inputTypes = goog.require('Blockly.inputTypes'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldLabel'); -goog.require('Blockly.inputTypes'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.RenderedConnection'); - /** * Class for an input with an optional field. * @param {number} type The type of the input. * @param {string} name Language-neutral identifier which may used to find this * input again. - * @param {!Blockly.Block} block The block containing this input. - * @param {Blockly.Connection} connection Optional connection for this input. + * @param {!Block} block The block containing this input. + * @param {Connection} connection Optional connection for this input. * @constructor */ const Input = function(type, name, block, connection) { - if (type != Blockly.inputTypes.DUMMY && !name) { + if (type != inputTypes.DUMMY && !name) { throw Error('Value inputs and statement inputs must have non-empty name.'); } /** @type {number} */ @@ -43,13 +47,13 @@ const Input = function(type, name, block, connection) { /** @type {string} */ this.name = name; /** - * @type {!Blockly.Block} + * @type {!Block} * @private */ this.sourceBlock_ = block; - /** @type {Blockly.Connection} */ + /** @type {Connection} */ this.connection = connection; - /** @type {!Array} */ + /** @type {!Array} */ this.fieldRow = []; }; @@ -57,7 +61,7 @@ const Input = function(type, name, block, connection) { * Alignment of input's fields (left, right or centre). * @type {number} */ -Input.prototype.align = Blockly.constants.ALIGN.LEFT; +Input.prototype.align = constants.ALIGN.LEFT; /** * Is the input visible? @@ -68,7 +72,7 @@ Input.prototype.visible_ = true; /** * Get the source block for this input. - * @return {?Blockly.Block} The source block, or null if there is none. + * @return {?Block} The source block, or null if there is none. */ Input.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -77,7 +81,7 @@ Input.prototype.getSourceBlock = function() { /** * Add a field (or label from string), and all prefix and suffix fields, to the * end of the input's field row. - * @param {string|!Blockly.Field} field Something to add as a field. + * @param {string|!Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. * @return {!Input} The input being append to (to allow chaining). @@ -91,7 +95,7 @@ Input.prototype.appendField = function(field, opt_name) { * Inserts a field (or label from string), and all prefix and suffix fields, at * the location of the input's field row. * @param {number} index The index at which to insert field. - * @param {string|!Blockly.Field} field Something to add as a field. + * @param {string|!Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. * @return {number} The index following the last inserted field. @@ -108,7 +112,7 @@ Input.prototype.insertFieldAt = function(index, field, opt_name) { // Generate a FieldLabel when given a plain text field. if (typeof field == 'string') { - field = /** @type {!Blockly.Field} **/ (Blockly.fieldRegistry.fromJson({ + field = /** @type {!Field} **/ (fieldRegistry.fromJson({ 'type': 'field_label', 'text': field, })); @@ -135,7 +139,7 @@ Input.prototype.insertFieldAt = function(index, field, opt_name) { } if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Adding a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -157,7 +161,7 @@ Input.prototype.removeField = function(name, opt_quiet) { field.dispose(); this.fieldRow.splice(i, 1); if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Removing a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -183,7 +187,7 @@ Input.prototype.isVisible = function() { * Sets whether this input is visible or not. * Should only be used to collapse/uncollapse a block. * @param {boolean} visible True if visible. - * @return {!Array} List of blocks to render. + * @return {!Array} List of blocks to render. * @package */ Input.prototype.setVisible = function(visible) { @@ -201,7 +205,7 @@ Input.prototype.setVisible = function(visible) { } if (this.connection) { this.connection = - /** @type {!Blockly.RenderedConnection} */ (this.connection); + /** @type {!RenderedConnection} */ (this.connection); // Has a connection. if (visible) { renderList = this.connection.startTrackingAll(); @@ -242,14 +246,14 @@ Input.prototype.setCheck = function(check) { /** * Change the alignment of the connection's field(s). - * @param {number} align One of the values of Blockly.constants.ALIGN. + * @param {number} align One of the values of constants.ALIGN. * In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left. * @return {!Input} The input being modified (to allow chaining). */ Input.prototype.setAlign = function(align) { this.align = align; if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); } return this; diff --git a/tests/deps.js b/tests/deps.js index f62333982..1cda35a7e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -70,7 +70,7 @@ goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.Block goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); From 761eec2b69dd20638171cf7a75302d1a79a89e3b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:56:17 -0700 Subject: [PATCH 4/4] clang-format core/input.js --- core/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/input.js b/core/input.js index 59c3b8a72..afa7a3358 100644 --- a/core/input.js +++ b/core/input.js @@ -205,7 +205,7 @@ Input.prototype.setVisible = function(visible) { } if (this.connection) { this.connection = - /** @type {!RenderedConnection} */ (this.connection); + /** @type {!RenderedConnection} */ (this.connection); // Has a connection. if (visible) { renderList = this.connection.startTrackingAll();