From fa158d143ec4f74a759557b232ae9d959401e122 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:48:33 -0700 Subject: [PATCH 1/5] Migrate core/connection.js to ES6 const/let --- core/connection.js | 82 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/core/connection.js b/core/connection.js index 27526c711..23d2193bd 100644 --- a/core/connection.js +++ b/core/connection.js @@ -104,10 +104,10 @@ Blockly.Connection.prototype.y = 0; * @protected */ Blockly.Connection.prototype.connect_ = function(childConnection) { - var INPUT = Blockly.connectionTypes.INPUT_VALUE; - var parentConnection = this; - var parentBlock = parentConnection.getSourceBlock(); - var childBlock = childConnection.getSourceBlock(); + const INPUT = Blockly.connectionTypes.INPUT_VALUE; + const parentConnection = this; + const parentBlock = parentConnection.getSourceBlock(); + const childBlock = childConnection.getSourceBlock(); // Make sure the childConnection is available. if (childConnection.isConnected()) { @@ -115,11 +115,11 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { } // Make sure the parentConnection is available. - var orphan; + let orphan; if (parentConnection.isConnected()) { - var shadowDom = parentConnection.getShadowDom(true); + const shadowDom = parentConnection.getShadowDom(true); parentConnection.shadowDom_ = null; // Set to null so it doesn't respawn. - var target = parentConnection.targetBlock(); + const target = parentConnection.targetBlock(); if (target.isShadow()) { target.dispose(false); } else { @@ -130,7 +130,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { } // Connect the new connection to the parent. - var event; + let event; if (Blockly.Events.isEnabled()) { event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } @@ -143,9 +143,9 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { // Deal with the orphan if it exists. if (orphan) { - var orphanConnection = parentConnection.type === INPUT ? + const orphanConnection = parentConnection.type === INPUT ? orphan.outputConnection : orphan.previousConnection; - var connection = Blockly.Connection.getConnectionForOrphanedConnection( + const connection = Blockly.Connection.getConnectionForOrphanedConnection( childBlock, /** @type {!Blockly.Connection} */ (orphanConnection)); if (connection) { orphanConnection.connect(connection); @@ -167,7 +167,7 @@ Blockly.Connection.prototype.dispose = function() { // Destroy the attached shadow block & its children (if it exists). this.setShadowDom(null); - var targetBlock = this.targetBlock(); + const targetBlock = this.targetBlock(); if (targetBlock) { // Disconnect the attached normal block. targetBlock.unplug(); @@ -236,8 +236,8 @@ Blockly.Connection.prototype.checkConnection = function(target) { 'July 2020', 'July 2021', 'the workspace\'s connection checker'); - var checker = this.getConnectionChecker(); - var reason = checker.canConnectWithReason(this, target, false); + const checker = this.getConnectionChecker(); + const reason = checker.canConnectWithReason(this, target, false); if (reason != Blockly.Connection.CAN_CONNECT) { throw new Error(checker.getErrorMessage(reason, this, target)); } @@ -290,9 +290,9 @@ Blockly.Connection.prototype.connect = function(otherConnection) { return; } - var checker = this.getConnectionChecker(); + const checker = this.getConnectionChecker(); if (checker.canConnect(this, otherConnection, false)) { - var eventGroup = Blockly.Events.getGroup(); + const eventGroup = Blockly.Events.getGroup(); if (!eventGroup) { Blockly.Events.setGroup(true); } @@ -336,12 +336,12 @@ Blockly.Connection.connectReciprocally_ = function(first, second) { * @private */ Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { - var foundConnection = null; - var output = orphanBlock.outputConnection; - var typeChecker = output.getConnectionChecker(); + let foundConnection = null; + const output = orphanBlock.outputConnection; + const typeChecker = output.getConnectionChecker(); - for (var i = 0, input; (input = block.inputList[i]); i++) { - var connection = input.connection; + for (let i = 0, input; (input = block.inputList[i]); i++) { + const connection = input.connection; if (connection && typeChecker.canConnect(output, connection, false)) { if (foundConnection) { return null; // More than one connection. @@ -366,8 +366,8 @@ Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { */ Blockly.Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { - var newBlock = startBlock; - var connection; + let newBlock = startBlock; + let connection; while ((connection = Blockly.Connection.getSingleConnection_( /** @type {!Blockly.Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); @@ -395,8 +395,8 @@ Blockly.Connection.getConnectionForOrphanedConnection = startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack. - var connection = startBlock.lastConnectionInStack(true); - var checker = orphanConnection.getConnectionChecker(); + const connection = startBlock.lastConnectionInStack(true); + const checker = orphanConnection.getConnectionChecker(); if (connection && checker.canConnect(orphanConnection, connection, false)) { return connection; @@ -408,14 +408,14 @@ Blockly.Connection.getConnectionForOrphanedConnection = * Disconnect this connection. */ Blockly.Connection.prototype.disconnect = function() { - var otherConnection = this.targetConnection; + const otherConnection = this.targetConnection; if (!otherConnection) { throw Error('Source connection not connected.'); } if (otherConnection.targetConnection != this) { throw Error('Target connection not connected to source connection.'); } - var parentBlock, childBlock, parentConnection; + let parentBlock, childBlock, parentConnection; if (this.isSuperior()) { // Superior block. parentBlock = this.sourceBlock_; @@ -428,7 +428,7 @@ Blockly.Connection.prototype.disconnect = function() { parentConnection = otherConnection; } - var eventGroup = Blockly.Events.getGroup(); + const eventGroup = Blockly.Events.getGroup(); if (!eventGroup) { Blockly.Events.setGroup(true); } @@ -450,11 +450,11 @@ Blockly.Connection.prototype.disconnect = function() { */ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { - var event; + let event; if (Blockly.Events.isEnabled()) { event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } - var otherConnection = this.targetConnection; + const otherConnection = this.targetConnection; otherConnection.targetConnection = null; this.targetConnection = null; childBlock.setParent(null); @@ -469,10 +469,10 @@ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, * @protected */ Blockly.Connection.prototype.respawnShadow_ = function() { - var parentBlock = this.getSourceBlock(); - var shadow = this.getShadowDom(); + const parentBlock = this.getSourceBlock(); + const shadow = this.getShadowDom(); if (parentBlock.workspace && shadow) { - var blockShadow = Blockly.Xml.domToBlock(shadow, parentBlock.workspace); + const blockShadow = Blockly.Xml.domToBlock(shadow, parentBlock.workspace); if (blockShadow.outputConnection) { this.connect(blockShadow.outputConnection); } else if (blockShadow.previousConnection) { @@ -540,7 +540,7 @@ Blockly.Connection.prototype.onCheckChanged_ = function() { if (this.isConnected() && (!this.targetConnection || !this.getConnectionChecker().canConnect( this, this.targetConnection, false))) { - var child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; + const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; child.unplug(); } }; @@ -582,7 +582,7 @@ Blockly.Connection.prototype.getCheck = function() { */ Blockly.Connection.prototype.setShadowDom = function(shadow) { this.shadowDom_ = shadow; - var target = this.targetBlock(); + const target = this.targetBlock(); if (!target) { this.respawnShadow_(); } else if (target.isShadow()) { @@ -630,9 +630,9 @@ Blockly.Connection.prototype.neighbours = function(_maxLimit) { * @package */ Blockly.Connection.prototype.getParentInput = function() { - var parentInput = null; - var inputs = this.sourceBlock_.inputList; - for (var i = 0; i < inputs.length; i++) { + let parentInput = null; + const inputs = this.sourceBlock_.inputList; + for (let i = 0; i < inputs.length; i++) { if (inputs[i].connection === this) { parentInput = inputs[i]; break; @@ -647,11 +647,11 @@ Blockly.Connection.prototype.getParentInput = function() { * @return {string} The description. */ Blockly.Connection.prototype.toString = function() { - var block = this.sourceBlock_; + const block = this.sourceBlock_; if (!block) { return 'Orphan Connection'; } - var msg; + let msg; if (block.outputConnection == this) { msg = 'Output Connection of '; } else if (block.previousConnection == this) { @@ -659,8 +659,8 @@ Blockly.Connection.prototype.toString = function() { } else if (block.nextConnection == this) { msg = 'Next Connection of '; } else { - var parentInput = null; - for (var i = 0, input; (input = block.inputList[i]); i++) { + let parentInput = null; + for (let i = 0, input; (input = block.inputList[i]); i++) { if (input.connection == this) { parentInput = input; break; From fc62fed33c94564449d521644bc0d44dbca739f9 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:55:08 -0700 Subject: [PATCH 2/5] Migrate core/connection.js to goog.module --- core/connection.js | 141 +++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 73 insertions(+), 70 deletions(-) diff --git a/core/connection.js b/core/connection.js index 23d2193bd..be9a08eb9 100644 --- a/core/connection.js +++ b/core/connection.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Connection'); +goog.module('Blockly.Connection'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ @@ -34,7 +35,7 @@ goog.requireType('Blockly.Input'); * @constructor * @implements {Blockly.IASTNodeLocationWithBlock} */ -Blockly.Connection = function(source, type) { +const Connection = function(source, type) { /** * @type {!Blockly.Block} * @protected @@ -47,63 +48,63 @@ Blockly.Connection = function(source, type) { /** * Constants for checking whether two connections are compatible. */ -Blockly.Connection.CAN_CONNECT = 0; -Blockly.Connection.REASON_SELF_CONNECTION = 1; -Blockly.Connection.REASON_WRONG_TYPE = 2; -Blockly.Connection.REASON_TARGET_NULL = 3; -Blockly.Connection.REASON_CHECKS_FAILED = 4; -Blockly.Connection.REASON_DIFFERENT_WORKSPACES = 5; -Blockly.Connection.REASON_SHADOW_PARENT = 6; -Blockly.Connection.REASON_DRAG_CHECKS_FAILED = 7; +Connection.CAN_CONNECT = 0; +Connection.REASON_SELF_CONNECTION = 1; +Connection.REASON_WRONG_TYPE = 2; +Connection.REASON_TARGET_NULL = 3; +Connection.REASON_CHECKS_FAILED = 4; +Connection.REASON_DIFFERENT_WORKSPACES = 5; +Connection.REASON_SHADOW_PARENT = 6; +Connection.REASON_DRAG_CHECKS_FAILED = 7; /** * Connection this connection connects to. Null if not connected. - * @type {Blockly.Connection} + * @type {Connection} */ -Blockly.Connection.prototype.targetConnection = null; +Connection.prototype.targetConnection = null; /** * Has this connection been disposed of? * @type {boolean} * @package */ -Blockly.Connection.prototype.disposed = false; +Connection.prototype.disposed = false; /** * List of compatible value types. Null if all types are compatible. * @type {Array} * @private */ -Blockly.Connection.prototype.check_ = null; +Connection.prototype.check_ = null; /** * DOM representation of a shadow block, or null if none. * @type {Element} * @private */ -Blockly.Connection.prototype.shadowDom_ = null; +Connection.prototype.shadowDom_ = null; /** * Horizontal location of this connection. * @type {number} * @package */ -Blockly.Connection.prototype.x = 0; +Connection.prototype.x = 0; /** * Vertical location of this connection. * @type {number} * @package */ -Blockly.Connection.prototype.y = 0; +Connection.prototype.y = 0; /** * Connect two connections together. This is the connection on the superior * block. - * @param {!Blockly.Connection} childConnection Connection on inferior block. + * @param {!Connection} childConnection Connection on inferior block. * @protected */ -Blockly.Connection.prototype.connect_ = function(childConnection) { +Connection.prototype.connect_ = function(childConnection) { const INPUT = Blockly.connectionTypes.INPUT_VALUE; const parentConnection = this; const parentBlock = parentConnection.getSourceBlock(); @@ -134,7 +135,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { if (Blockly.Events.isEnabled()) { event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } - Blockly.Connection.connectReciprocally_(parentConnection, childConnection); + Connection.connectReciprocally_(parentConnection, childConnection); childBlock.setParent(parentBlock); if (event) { event.recordNew(); @@ -145,8 +146,8 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { if (orphan) { const orphanConnection = parentConnection.type === INPUT ? orphan.outputConnection : orphan.previousConnection; - const connection = Blockly.Connection.getConnectionForOrphanedConnection( - childBlock, /** @type {!Blockly.Connection} */ (orphanConnection)); + const connection = Connection.getConnectionForOrphanedConnection( + childBlock, /** @type {!Connection} */ (orphanConnection)); if (connection) { orphanConnection.connect(connection); } else { @@ -160,7 +161,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { * Dispose of this connection and deal with connected blocks. * @package */ -Blockly.Connection.prototype.dispose = function() { +Connection.prototype.dispose = function() { // isConnected returns true for shadows and non-shadows. if (this.isConnected()) { @@ -181,7 +182,7 @@ Blockly.Connection.prototype.dispose = function() { * Get the source block for this connection. * @return {!Blockly.Block} The source block. */ -Blockly.Connection.prototype.getSourceBlock = function() { +Connection.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -189,7 +190,7 @@ Blockly.Connection.prototype.getSourceBlock = function() { * Does the connection belong to a superior block (higher in the source stack)? * @return {boolean} True if connection faces down or right. */ -Blockly.Connection.prototype.isSuperior = function() { +Connection.prototype.isSuperior = function() { return this.type == Blockly.connectionTypes.INPUT_VALUE || this.type == Blockly.connectionTypes.NEXT_STATEMENT; }; @@ -198,20 +199,20 @@ Blockly.Connection.prototype.isSuperior = function() { * Is the connection connected? * @return {boolean} True if connection is connected to another connection. */ -Blockly.Connection.prototype.isConnected = function() { +Connection.prototype.isConnected = function() { return !!this.targetConnection; }; /** * Checks whether the current connection can connect with the target * connection. - * @param {Blockly.Connection} target Connection to check compatibility with. - * @return {number} Blockly.Connection.CAN_CONNECT if the connection is legal, + * @param {Connection} target Connection to check compatibility with. + * @return {number} Connection.CAN_CONNECT if the connection is legal, * an error code otherwise. * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.canConnectWithReason = function(target) { +Connection.prototype.canConnectWithReason = function(target) { Blockly.utils.deprecation.warn( 'Connection.prototype.canConnectWithReason', 'July 2020', @@ -224,13 +225,13 @@ Blockly.Connection.prototype.canConnectWithReason = function(target) { /** * Checks whether the current connection and target connection are compatible * and throws an exception if they are not. - * @param {Blockly.Connection} target The connection to check compatibility + * @param {Connection} target The connection to check compatibility * with. * @package * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.checkConnection = function(target) { +Connection.prototype.checkConnection = function(target) { Blockly.utils.deprecation.warn( 'Connection.prototype.checkConnection', 'July 2020', @@ -238,7 +239,7 @@ Blockly.Connection.prototype.checkConnection = function(target) { 'the workspace\'s connection checker'); const checker = this.getConnectionChecker(); const reason = checker.canConnectWithReason(this, target, false); - if (reason != Blockly.Connection.CAN_CONNECT) { + if (reason != Connection.CAN_CONNECT) { throw new Error(checker.getErrorMessage(reason, this, target)); } }; @@ -249,18 +250,18 @@ Blockly.Connection.prototype.checkConnection = function(target) { * source block's workspace. * @package */ -Blockly.Connection.prototype.getConnectionChecker = function() { +Connection.prototype.getConnectionChecker = function() { return this.sourceBlock_.workspace.connectionChecker; }; /** * Check if the two connections can be dragged to connect to each other. - * @param {!Blockly.Connection} candidate A nearby connection to check. + * @param {!Connection} candidate A nearby connection to check. * @return {boolean} True if the connection is allowed, false otherwise. * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.isConnectionAllowed = function(candidate) { +Connection.prototype.isConnectionAllowed = function(candidate) { Blockly.utils.deprecation.warn( 'Connection.prototype.isConnectionAllowed', 'July 2020', @@ -272,19 +273,19 @@ Blockly.Connection.prototype.isConnectionAllowed = function(candidate) { /** * Called when an attempted connection fails. NOP by default (i.e. for headless * workspaces). - * @param {!Blockly.Connection} _otherConnection Connection that this connection + * @param {!Connection} _otherConnection Connection that this connection * failed to connect to. * @package */ -Blockly.Connection.prototype.onFailedConnect = function(_otherConnection) { +Connection.prototype.onFailedConnect = function(_otherConnection) { // NOP }; /** * Connect this connection to another connection. - * @param {!Blockly.Connection} otherConnection Connection to connect to. + * @param {!Connection} otherConnection Connection to connect to. */ -Blockly.Connection.prototype.connect = function(otherConnection) { +Connection.prototype.connect = function(otherConnection) { if (this.targetConnection == otherConnection) { // Already connected together. NOP. return; @@ -312,11 +313,11 @@ Blockly.Connection.prototype.connect = function(otherConnection) { /** * Update two connections to target each other. - * @param {Blockly.Connection} first The first connection to update. - * @param {Blockly.Connection} second The second connection to update. + * @param {Connection} first The first connection to update. + * @param {Connection} second The second connection to update. * @private */ -Blockly.Connection.connectReciprocally_ = function(first, second) { +Connection.connectReciprocally_ = function(first, second) { if (!first || !second) { throw Error('Cannot connect null connections.'); } @@ -331,11 +332,11 @@ Blockly.Connection.connectReciprocally_ = function(first, second) { * connections, this returns null. * @param {!Blockly.Block} block The superior block. * @param {!Blockly.Block} orphanBlock The inferior block. - * @return {?Blockly.Connection} The suitable connection point on 'block', + * @return {?Connection} The suitable connection point on 'block', * or null. * @private */ -Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { +Connection.getSingleConnection_ = function(block, orphanBlock) { let foundConnection = null; const output = orphanBlock.outputConnection; const typeChecker = output.getConnectionChecker(); @@ -360,15 +361,15 @@ Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { * Terminates early for shadow blocks. * @param {!Blockly.Block} startBlock The block on which to start the search. * @param {!Blockly.Block} orphanBlock The block that is looking for a home. - * @return {?Blockly.Connection} The suitable connection point on the chain + * @return {?Connection} The suitable connection point on the chain * of blocks, or null. * @private */ -Blockly.Connection.getConnectionForOrphanedOutput_ = +Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { let newBlock = startBlock; let connection; - while ((connection = Blockly.Connection.getSingleConnection_( + while ((connection = Connection.getSingleConnection_( /** @type {!Blockly.Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); if (!newBlock || newBlock.isShadow()) { @@ -383,15 +384,15 @@ Blockly.Connection.getConnectionForOrphanedOutput_ = * the given connection. This includes compatible connection types and * connection checks. * @param {!Blockly.Block} startBlock The block on which to start the search. - * @param {!Blockly.Connection} orphanConnection The connection that is looking + * @param {!Connection} orphanConnection The connection that is looking * for a home. - * @return {?Blockly.Connection} The suitable connection point on the chain of + * @return {?Connection} The suitable connection point on the chain of * blocks, or null. */ -Blockly.Connection.getConnectionForOrphanedConnection = +Connection.getConnectionForOrphanedConnection = function(startBlock, orphanConnection) { if (orphanConnection.type === Blockly.connectionTypes.OUTPUT_VALUE) { - return Blockly.Connection.getConnectionForOrphanedOutput_( + return Connection.getConnectionForOrphanedOutput_( startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack. @@ -407,7 +408,7 @@ Blockly.Connection.getConnectionForOrphanedConnection = /** * Disconnect this connection. */ -Blockly.Connection.prototype.disconnect = function() { +Connection.prototype.disconnect = function() { const otherConnection = this.targetConnection; if (!otherConnection) { throw Error('Source connection not connected.'); @@ -448,7 +449,7 @@ Blockly.Connection.prototype.disconnect = function() { * @param {!Blockly.Block} childBlock The inferior block. * @protected */ -Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, +Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { let event; if (Blockly.Events.isEnabled()) { @@ -468,7 +469,7 @@ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, * Respawn the shadow block if there was one connected to the this connection. * @protected */ -Blockly.Connection.prototype.respawnShadow_ = function() { +Connection.prototype.respawnShadow_ = function() { const parentBlock = this.getSourceBlock(); const shadow = this.getShadowDom(); if (parentBlock.workspace && shadow) { @@ -487,7 +488,7 @@ Blockly.Connection.prototype.respawnShadow_ = function() { * Returns the block that this connection connects to. * @return {?Blockly.Block} The connected block or null if none is connected. */ -Blockly.Connection.prototype.targetBlock = function() { +Connection.prototype.targetBlock = function() { if (this.isConnected()) { return this.targetConnection.getSourceBlock(); } @@ -497,12 +498,12 @@ Blockly.Connection.prototype.targetBlock = function() { /** * Is this connection compatible with another connection with respect to the * value type system. E.g. square_root("Hello") is not compatible. - * @param {!Blockly.Connection} otherConnection Connection to compare against. + * @param {!Connection} otherConnection Connection to compare against. * @return {boolean} True if the connections share a type. * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.checkType = function(otherConnection) { +Connection.prototype.checkType = function(otherConnection) { Blockly.utils.deprecation.warn( 'Connection.prototype.checkType', 'October 2019', @@ -515,14 +516,14 @@ Blockly.Connection.prototype.checkType = function(otherConnection) { /** * Is this connection compatible with another connection with respect to the * value type system. E.g. square_root("Hello") is not compatible. - * @param {!Blockly.Connection} otherConnection Connection to compare against. + * @param {!Connection} otherConnection Connection to compare against. * @return {boolean} True if the connections share a type. * @private * @deprecated October 2019. Will be deleted January 2021. Use the workspace's * connectionChecker instead. * @suppress {unusedPrivateMembers} */ -Blockly.Connection.prototype.checkType_ = function(otherConnection) { +Connection.prototype.checkType_ = function(otherConnection) { Blockly.utils.deprecation.warn( 'Connection.prototype.checkType_', 'October 2019', @@ -535,7 +536,7 @@ Blockly.Connection.prototype.checkType_ = function(otherConnection) { * Function to be called when this connection's compatible types have changed. * @protected */ -Blockly.Connection.prototype.onCheckChanged_ = function() { +Connection.prototype.onCheckChanged_ = function() { // The new value type may not be compatible with the existing connection. if (this.isConnected() && (!this.targetConnection || !this.getConnectionChecker().canConnect( @@ -549,10 +550,10 @@ Blockly.Connection.prototype.onCheckChanged_ = function() { * Change a connection's compatibility. * @param {?(string|!Array)} check Compatible value type or list of * value types. Null if all types are compatible. - * @return {!Blockly.Connection} The connection being modified + * @return {!Connection} The connection being modified * (to allow chaining). */ -Blockly.Connection.prototype.setCheck = function(check) { +Connection.prototype.setCheck = function(check) { if (check) { // Ensure that check is in an array. if (!Array.isArray(check)) { @@ -572,7 +573,7 @@ Blockly.Connection.prototype.setCheck = function(check) { * Null if all types are compatible. * @public */ -Blockly.Connection.prototype.getCheck = function() { +Connection.prototype.getCheck = function() { return this.check_; }; @@ -580,7 +581,7 @@ Blockly.Connection.prototype.getCheck = function() { * Changes the connection's shadow block. * @param {?Element} shadow DOM representation of a block or null. */ -Blockly.Connection.prototype.setShadowDom = function(shadow) { +Connection.prototype.setShadowDom = function(shadow) { this.shadowDom_ = shadow; const target = this.targetBlock(); if (!target) { @@ -600,7 +601,7 @@ Blockly.Connection.prototype.setShadowDom = function(shadow) { * shadowDom is just returned. * @return {?Element} Shadow DOM representation of a block or null. */ -Blockly.Connection.prototype.getShadowDom = function(returnCurrent) { +Connection.prototype.getShadowDom = function(returnCurrent) { return (returnCurrent && this.targetBlock().isShadow()) ? /** @type {!Element} */ (Blockly.Xml.blockToDom( /** @type {!Blockly.Block} */ (this.targetBlock()))) : @@ -616,10 +617,10 @@ Blockly.Connection.prototype.getShadowDom = function(returnCurrent) { * {@link Blockly.RenderedConnection} overrides this behavior with a list * computed from the rendered positioning. * @param {number} _maxLimit The maximum radius to another connection. - * @return {!Array} List of connections. + * @return {!Array} List of connections. * @package */ -Blockly.Connection.prototype.neighbours = function(_maxLimit) { +Connection.prototype.neighbours = function(_maxLimit) { return []; }; @@ -629,7 +630,7 @@ Blockly.Connection.prototype.neighbours = function(_maxLimit) { * no parent exists. * @package */ -Blockly.Connection.prototype.getParentInput = function() { +Connection.prototype.getParentInput = function() { let parentInput = null; const inputs = this.sourceBlock_.inputList; for (let i = 0; i < inputs.length; i++) { @@ -646,7 +647,7 @@ Blockly.Connection.prototype.getParentInput = function() { * (English only). Intended to on be used in console logs and errors. * @return {string} The description. */ -Blockly.Connection.prototype.toString = function() { +Connection.prototype.toString = function() { const block = this.sourceBlock_; if (!block) { return 'Orphan Connection'; @@ -675,3 +676,5 @@ Blockly.Connection.prototype.toString = function() { } return msg + block.toDevString(); }; + +exports = Connection; diff --git a/tests/deps.js b/tests/deps.js index ed2af0dc9..b435a26ba 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -19,7 +19,7 @@ goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); From 210fcea19889f19c008899e3f89a1837d76a8174 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:13:40 -0700 Subject: [PATCH 3/5] Migrate core/connection.js to named requires --- core/connection.js | 95 +++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/core/connection.js b/core/connection.js index be9a08eb9..0c7f54605 100644 --- a/core/connection.js +++ b/core/connection.js @@ -13,31 +13,30 @@ goog.module('Blockly.Connection'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const Block = goog.requireType('Blockly.Block'); +const deprecation = goog.require('Blockly.utils.deprecation'); +const Events = goog.require('Blockly.Events'); +const IASTNodeLocationWithBlock = goog.require('Blockly.IASTNodeLocationWithBlock'); +const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +const Input = goog.requireType('Blockly.Input'); +const Xml = goog.require('Blockly.Xml'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -goog.require('Blockly.IASTNodeLocationWithBlock'); -goog.require('Blockly.utils.deprecation'); -goog.require('Blockly.Xml'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.IConnectionChecker'); -goog.requireType('Blockly.Input'); /** * Class for a connection between blocks. - * @param {!Blockly.Block} source The block establishing this connection. + * @param {!Block} source The block establishing this connection. * @param {number} type The type of the connection. * @constructor - * @implements {Blockly.IASTNodeLocationWithBlock} + * @implements {IASTNodeLocationWithBlock} */ const Connection = function(source, type) { /** - * @type {!Blockly.Block} + * @type {!Block} * @protected */ this.sourceBlock_ = source; @@ -105,7 +104,7 @@ Connection.prototype.y = 0; * @protected */ Connection.prototype.connect_ = function(childConnection) { - const INPUT = Blockly.connectionTypes.INPUT_VALUE; + const INPUT = connectionTypes.INPUT_VALUE; const parentConnection = this; const parentBlock = parentConnection.getSourceBlock(); const childBlock = childConnection.getSourceBlock(); @@ -132,14 +131,14 @@ Connection.prototype.connect_ = function(childConnection) { // Connect the new connection to the parent. let event; - if (Blockly.Events.isEnabled()) { - event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); + if (Events.isEnabled()) { + event = new (Events.get(Events.BLOCK_MOVE))(childBlock); } Connection.connectReciprocally_(parentConnection, childConnection); childBlock.setParent(parentBlock); if (event) { event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); } // Deal with the orphan if it exists. @@ -180,7 +179,7 @@ Connection.prototype.dispose = function() { /** * Get the source block for this connection. - * @return {!Blockly.Block} The source block. + * @return {!Block} The source block. */ Connection.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -191,8 +190,8 @@ Connection.prototype.getSourceBlock = function() { * @return {boolean} True if connection faces down or right. */ Connection.prototype.isSuperior = function() { - return this.type == Blockly.connectionTypes.INPUT_VALUE || - this.type == Blockly.connectionTypes.NEXT_STATEMENT; + return this.type == connectionTypes.INPUT_VALUE || + this.type == connectionTypes.NEXT_STATEMENT; }; /** @@ -213,7 +212,7 @@ Connection.prototype.isConnected = function() { * connectionChecker instead. */ Connection.prototype.canConnectWithReason = function(target) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.canConnectWithReason', 'July 2020', 'July 2021', @@ -232,7 +231,7 @@ Connection.prototype.canConnectWithReason = function(target) { * connectionChecker instead. */ Connection.prototype.checkConnection = function(target) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.checkConnection', 'July 2020', 'July 2021', @@ -246,7 +245,7 @@ Connection.prototype.checkConnection = function(target) { /** * Get the workspace's connection type checker object. - * @return {!Blockly.IConnectionChecker} The connection type checker for the + * @return {!IConnectionChecker} The connection type checker for the * source block's workspace. * @package */ @@ -262,7 +261,7 @@ Connection.prototype.getConnectionChecker = function() { * connectionChecker instead. */ Connection.prototype.isConnectionAllowed = function(candidate) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', @@ -293,9 +292,9 @@ Connection.prototype.connect = function(otherConnection) { const checker = this.getConnectionChecker(); if (checker.canConnect(this, otherConnection, false)) { - const eventGroup = Blockly.Events.getGroup(); + const eventGroup = Events.getGroup(); if (!eventGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } // Determine which block is superior (higher in the source stack). if (this.isSuperior()) { @@ -306,7 +305,7 @@ Connection.prototype.connect = function(otherConnection) { otherConnection.connect_(this); } if (!eventGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } } }; @@ -330,8 +329,8 @@ Connection.connectReciprocally_ = function(first, second) { * block, if one can be found. If the block has multiple compatible connections * (even if they are filled) this returns null. If the block has no compatible * connections, this returns null. - * @param {!Blockly.Block} block The superior block. - * @param {!Blockly.Block} orphanBlock The inferior block. + * @param {!Block} block The superior block. + * @param {!Block} orphanBlock The inferior block. * @return {?Connection} The suitable connection point on 'block', * or null. * @private @@ -359,8 +358,8 @@ Connection.getSingleConnection_ = function(block, orphanBlock) { * are zero or multiple eligible connections, returns null. Otherwise * returns the only input on the last block in the chain. * Terminates early for shadow blocks. - * @param {!Blockly.Block} startBlock The block on which to start the search. - * @param {!Blockly.Block} orphanBlock The block that is looking for a home. + * @param {!Block} startBlock The block on which to start the search. + * @param {!Block} orphanBlock The block that is looking for a home. * @return {?Connection} The suitable connection point on the chain * of blocks, or null. * @private @@ -370,7 +369,7 @@ Connection.getConnectionForOrphanedOutput_ = let newBlock = startBlock; let connection; while ((connection = Connection.getSingleConnection_( - /** @type {!Blockly.Block} */ (newBlock), orphanBlock))) { + /** @type {!Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); if (!newBlock || newBlock.isShadow()) { return connection; @@ -383,7 +382,7 @@ Connection.getConnectionForOrphanedOutput_ = * Returns the connection (starting at the startBlock) which will accept * the given connection. This includes compatible connection types and * connection checks. - * @param {!Blockly.Block} startBlock The block on which to start the search. + * @param {!Block} startBlock The block on which to start the search. * @param {!Connection} orphanConnection The connection that is looking * for a home. * @return {?Connection} The suitable connection point on the chain of @@ -391,7 +390,7 @@ Connection.getConnectionForOrphanedOutput_ = */ Connection.getConnectionForOrphanedConnection = function(startBlock, orphanConnection) { - if (orphanConnection.type === Blockly.connectionTypes.OUTPUT_VALUE) { + if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { return Connection.getConnectionForOrphanedOutput_( startBlock, orphanConnection.getSourceBlock()); } @@ -429,9 +428,9 @@ Connection.prototype.disconnect = function() { parentConnection = otherConnection; } - const eventGroup = Blockly.Events.getGroup(); + const eventGroup = Events.getGroup(); if (!eventGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } this.disconnectInternal_(parentBlock, childBlock); if (!childBlock.isShadow()) { @@ -439,21 +438,21 @@ Connection.prototype.disconnect = function() { parentConnection.respawnShadow_(); } if (!eventGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } }; /** * Disconnect two blocks that are connected by this connection. - * @param {!Blockly.Block} parentBlock The superior block. - * @param {!Blockly.Block} childBlock The inferior block. + * @param {!Block} parentBlock The superior block. + * @param {!Block} childBlock The inferior block. * @protected */ Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { let event; - if (Blockly.Events.isEnabled()) { - event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); + if (Events.isEnabled()) { + event = new (Events.get(Events.BLOCK_MOVE))(childBlock); } const otherConnection = this.targetConnection; otherConnection.targetConnection = null; @@ -461,7 +460,7 @@ Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock.setParent(null); if (event) { event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); } }; @@ -473,7 +472,7 @@ Connection.prototype.respawnShadow_ = function() { const parentBlock = this.getSourceBlock(); const shadow = this.getShadowDom(); if (parentBlock.workspace && shadow) { - const blockShadow = Blockly.Xml.domToBlock(shadow, parentBlock.workspace); + const blockShadow = Xml.domToBlock(shadow, parentBlock.workspace); if (blockShadow.outputConnection) { this.connect(blockShadow.outputConnection); } else if (blockShadow.previousConnection) { @@ -486,7 +485,7 @@ Connection.prototype.respawnShadow_ = function() { /** * Returns the block that this connection connects to. - * @return {?Blockly.Block} The connected block or null if none is connected. + * @return {?Block} The connected block or null if none is connected. */ Connection.prototype.targetBlock = function() { if (this.isConnected()) { @@ -504,7 +503,7 @@ Connection.prototype.targetBlock = function() { * connectionChecker instead. */ Connection.prototype.checkType = function(otherConnection) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.checkType', 'October 2019', 'January 2021', @@ -524,7 +523,7 @@ Connection.prototype.checkType = function(otherConnection) { * @suppress {unusedPrivateMembers} */ Connection.prototype.checkType_ = function(otherConnection) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.checkType_', 'October 2019', 'January 2021', @@ -603,8 +602,8 @@ Connection.prototype.setShadowDom = function(shadow) { */ Connection.prototype.getShadowDom = function(returnCurrent) { return (returnCurrent && this.targetBlock().isShadow()) ? - /** @type {!Element} */ (Blockly.Xml.blockToDom( - /** @type {!Blockly.Block} */ (this.targetBlock()))) : + /** @type {!Element} */ (Xml.blockToDom( + /** @type {!Block} */ (this.targetBlock()))) : this.shadowDom_; }; @@ -626,7 +625,7 @@ Connection.prototype.neighbours = function(_maxLimit) { /** * Get the parent input of a connection. - * @return {?Blockly.Input} The input that the connection belongs to or null if + * @return {?Input} The input that the connection belongs to or null if * no parent exists. * @package */ From bdd0353549c57936601e884fcaffc5c4e209db70 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:16:06 -0700 Subject: [PATCH 4/5] clang-format core/connection.js --- core/connection.js | 95 ++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 54 deletions(-) diff --git a/core/connection.js b/core/connection.js index 0c7f54605..0b26e9ace 100644 --- a/core/connection.js +++ b/core/connection.js @@ -144,7 +144,8 @@ Connection.prototype.connect_ = function(childConnection) { // Deal with the orphan if it exists. if (orphan) { const orphanConnection = parentConnection.type === INPUT ? - orphan.outputConnection : orphan.previousConnection; + orphan.outputConnection : + orphan.previousConnection; const connection = Connection.getConnectionForOrphanedConnection( childBlock, /** @type {!Connection} */ (orphanConnection)); if (connection) { @@ -161,7 +162,6 @@ Connection.prototype.connect_ = function(childConnection) { * @package */ Connection.prototype.dispose = function() { - // isConnected returns true for shadows and non-shadows. if (this.isConnected()) { // Destroy the attached shadow block & its children (if it exists). @@ -213,12 +213,9 @@ Connection.prototype.isConnected = function() { */ Connection.prototype.canConnectWithReason = function(target) { deprecation.warn( - 'Connection.prototype.canConnectWithReason', - 'July 2020', - 'July 2021', + 'Connection.prototype.canConnectWithReason', 'July 2020', 'July 2021', 'the workspace\'s connection checker'); - return this.getConnectionChecker().canConnectWithReason( - this, target, false); + return this.getConnectionChecker().canConnectWithReason(this, target, false); }; /** @@ -232,9 +229,7 @@ Connection.prototype.canConnectWithReason = function(target) { */ Connection.prototype.checkConnection = function(target) { deprecation.warn( - 'Connection.prototype.checkConnection', - 'July 2020', - 'July 2021', + 'Connection.prototype.checkConnection', 'July 2020', 'July 2021', 'the workspace\'s connection checker'); const checker = this.getConnectionChecker(); const reason = checker.canConnectWithReason(this, target, false); @@ -262,9 +257,7 @@ Connection.prototype.getConnectionChecker = function() { */ Connection.prototype.isConnectionAllowed = function(candidate) { deprecation.warn( - 'Connection.prototype.isConnectionAllowed', - 'July 2020', - 'July 2021', + 'Connection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', 'the workspace\'s connection checker'); return this.getConnectionChecker().canConnect(this, candidate, true); }; @@ -364,19 +357,19 @@ Connection.getSingleConnection_ = function(block, orphanBlock) { * of blocks, or null. * @private */ -Connection.getConnectionForOrphanedOutput_ = - function(startBlock, orphanBlock) { - let newBlock = startBlock; - let connection; - while ((connection = Connection.getSingleConnection_( - /** @type {!Block} */ (newBlock), orphanBlock))) { - newBlock = connection.targetBlock(); - if (!newBlock || newBlock.isShadow()) { - return connection; - } - } - return null; - }; +Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { + let newBlock = startBlock; + let connection; + while ( + (connection = Connection.getSingleConnection_( + /** @type {!Block} */ (newBlock), orphanBlock))) { + newBlock = connection.targetBlock(); + if (!newBlock || newBlock.isShadow()) { + return connection; + } + } + return null; +}; /** * Returns the connection (starting at the startBlock) which will accept @@ -388,21 +381,20 @@ Connection.getConnectionForOrphanedOutput_ = * @return {?Connection} The suitable connection point on the chain of * blocks, or null. */ -Connection.getConnectionForOrphanedConnection = - function(startBlock, orphanConnection) { - if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { - return Connection.getConnectionForOrphanedOutput_( - startBlock, orphanConnection.getSourceBlock()); - } - // Otherwise we're dealing with a stack. - const connection = startBlock.lastConnectionInStack(true); - const checker = orphanConnection.getConnectionChecker(); - if (connection && - checker.canConnect(orphanConnection, connection, false)) { - return connection; - } - return null; - }; +Connection.getConnectionForOrphanedConnection = function( + startBlock, orphanConnection) { + if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { + return Connection.getConnectionForOrphanedOutput_( + startBlock, orphanConnection.getSourceBlock()); + } + // Otherwise we're dealing with a stack. + const connection = startBlock.lastConnectionInStack(true); + const checker = orphanConnection.getConnectionChecker(); + if (connection && checker.canConnect(orphanConnection, connection, false)) { + return connection; + } + return null; +}; /** * Disconnect this connection. @@ -448,8 +440,7 @@ Connection.prototype.disconnect = function() { * @param {!Block} childBlock The inferior block. * @protected */ -Connection.prototype.disconnectInternal_ = function(parentBlock, - childBlock) { +Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { let event; if (Events.isEnabled()) { event = new (Events.get(Events.BLOCK_MOVE))(childBlock); @@ -504,12 +495,9 @@ Connection.prototype.targetBlock = function() { */ Connection.prototype.checkType = function(otherConnection) { deprecation.warn( - 'Connection.prototype.checkType', - 'October 2019', - 'January 2021', + 'Connection.prototype.checkType', 'October 2019', 'January 2021', 'the workspace\'s connection checker'); - return this.getConnectionChecker().canConnect(this, otherConnection, - false); + return this.getConnectionChecker().canConnect(this, otherConnection, false); }; /** @@ -524,9 +512,7 @@ Connection.prototype.checkType = function(otherConnection) { */ Connection.prototype.checkType_ = function(otherConnection) { deprecation.warn( - 'Connection.prototype.checkType_', - 'October 2019', - 'January 2021', + 'Connection.prototype.checkType_', 'October 2019', 'January 2021', 'the workspace\'s connection checker'); return this.checkType(otherConnection); }; @@ -537,9 +523,10 @@ Connection.prototype.checkType_ = function(otherConnection) { */ Connection.prototype.onCheckChanged_ = function() { // The new value type may not be compatible with the existing connection. - if (this.isConnected() && (!this.targetConnection || - !this.getConnectionChecker().canConnect( - this, this.targetConnection, false))) { + if (this.isConnected() && + (!this.targetConnection || + !this.getConnectionChecker().canConnect( + this, this.targetConnection, false))) { const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; child.unplug(); } From da960d5973912c660d802b2d3c4850b58d25b0ff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 20 Jul 2021 10:49:21 -0700 Subject: [PATCH 5/5] Convert private static functions to module-internal functions in core/connection.js --- core/connection.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core/connection.js b/core/connection.js index 0b26e9ace..553938825 100644 --- a/core/connection.js +++ b/core/connection.js @@ -134,7 +134,7 @@ Connection.prototype.connect_ = function(childConnection) { if (Events.isEnabled()) { event = new (Events.get(Events.BLOCK_MOVE))(childBlock); } - Connection.connectReciprocally_(parentConnection, childConnection); + connectReciprocally(parentConnection, childConnection); childBlock.setParent(parentBlock); if (event) { event.recordNew(); @@ -307,9 +307,8 @@ Connection.prototype.connect = function(otherConnection) { * Update two connections to target each other. * @param {Connection} first The first connection to update. * @param {Connection} second The second connection to update. - * @private */ -Connection.connectReciprocally_ = function(first, second) { +const connectReciprocally = function(first, second) { if (!first || !second) { throw Error('Cannot connect null connections.'); } @@ -326,9 +325,8 @@ Connection.connectReciprocally_ = function(first, second) { * @param {!Block} orphanBlock The inferior block. * @return {?Connection} The suitable connection point on 'block', * or null. - * @private */ -Connection.getSingleConnection_ = function(block, orphanBlock) { +const getSingleConnection = function(block, orphanBlock) { let foundConnection = null; const output = orphanBlock.outputConnection; const typeChecker = output.getConnectionChecker(); @@ -355,13 +353,12 @@ Connection.getSingleConnection_ = function(block, orphanBlock) { * @param {!Block} orphanBlock The block that is looking for a home. * @return {?Connection} The suitable connection point on the chain * of blocks, or null. - * @private */ -Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { +const getConnectionForOrphanedOutput = function(startBlock, orphanBlock) { let newBlock = startBlock; let connection; while ( - (connection = Connection.getSingleConnection_( + (connection = getSingleConnection( /** @type {!Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); if (!newBlock || newBlock.isShadow()) { @@ -384,7 +381,7 @@ Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { Connection.getConnectionForOrphanedConnection = function( startBlock, orphanConnection) { if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { - return Connection.getConnectionForOrphanedOutput_( + return getConnectionForOrphanedOutput( startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack.