From 23a0b89fc10b404a5eea46f5552f969d8d9d2c42 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 6 Aug 2021 12:30:30 -0700 Subject: [PATCH] Migrate core/block.js to goog.module syntax (#5322) * Migrate core/block.js to ES6 const/let * Migrate core/block.js to goog.module * Migrate core/block.js to ES6 const/let * Migrate core/block.js to goog.module * Migrate core/block.js to named requires * clang-format core/block.js * Add missing period to comment in core/block.js --- core/block.js | 865 +++++++++++++++++++++++++------------------------- tests/deps.js | 2 +- 2 files changed, 439 insertions(+), 428 deletions(-) diff --git a/core/block.js b/core/block.js index cfeaddebd..adddfe5ec 100644 --- a/core/block.js +++ b/core/block.js @@ -10,15 +10,40 @@ */ 'use strict'; -goog.provide('Blockly.Block'); +goog.module('Blockly.Block'); +goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); -goog.require('Blockly.Blocks'); -goog.require('Blockly.Connection'); -goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Abstract = goog.requireType('Blockly.Events.Abstract'); +const ASTNode = goog.require('Blockly.ASTNode'); +const Blocks = goog.require('Blockly.Blocks'); +/* eslint-disable-next-line no-unused-vars */ +const Comment = goog.requireType('Blockly.Comment'); +const Connection = goog.require('Blockly.Connection'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Events = goog.require('Blockly.Events'); +const Extensions = goog.require('Blockly.Extensions'); +/* eslint-disable-next-line no-unused-vars */ +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); +/* eslint-disable-next-line no-unused-vars */ +const IDeletable = goog.require('Blockly.IDeletable'); +const Input = goog.require('Blockly.Input'); +/* eslint-disable-next-line no-unused-vars */ +const Mutator = goog.requireType('Blockly.Mutator'); +const Size = goog.require('Blockly.utils.Size'); +const Tooltip = goog.require('Blockly.Tooltip'); +/* eslint-disable-next-line no-unused-vars */ +const VariableModel = goog.requireType('Blockly.VariableModel'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const constants = goog.require('Blockly.constants'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const inputTypes = goog.require('Blockly.inputTypes'); +const object = goog.require('Blockly.utils.object'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -27,59 +52,41 @@ goog.require('Blockly.Events.BlockCreate'); goog.require('Blockly.Events.BlockDelete'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -goog.require('Blockly.Extensions'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.IASTNodeLocation'); -goog.require('Blockly.IDeletable'); -goog.require('Blockly.Input'); -goog.require('Blockly.inputTypes'); -goog.require('Blockly.Tooltip'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.Workspace'); - -goog.requireType('Blockly.Comment'); -goog.requireType('Blockly.Events.Abstract'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.Mutator'); -goog.requireType('Blockly.utils.Size'); -goog.requireType('Blockly.VariableModel'); /** * Class for one block. * Not normally called directly, workspace.newBlock() is preferred. - * @param {!Blockly.Workspace} workspace The block's workspace. + * @param {!Workspace} workspace The block's workspace. * @param {!string} prototypeName Name of the language object containing * type-specific functions for this block. * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise * create a new ID. * @constructor - * @implements {Blockly.IASTNodeLocation} - * @implements {Blockly.IDeletable} + * @implements {IASTNodeLocation} + * @implements {IDeletable} * @throws When the prototypeName is not valid or not allowed. */ -Blockly.Block = function(workspace, prototypeName, opt_id) { - if (Blockly.Generator && - typeof Blockly.Generator.prototype[prototypeName] != 'undefined') { +const Block = function(workspace, prototypeName, opt_id) { + const Generator = goog.module.get('Blockly.Generator'); + if (Generator && typeof Generator.prototype[prototypeName] != 'undefined') { // Occluding Generator class members is not allowed. - throw Error('Block prototypeName "' + prototypeName + + throw Error( + 'Block prototypeName "' + prototypeName + '" conflicts with Blockly.Generator members.'); } /** @type {string} */ - this.id = (opt_id && !workspace.getBlockById(opt_id)) ? - opt_id : Blockly.utils.genUid(); + this.id = + (opt_id && !workspace.getBlockById(opt_id)) ? opt_id : utils.genUid(); workspace.setBlockById(this.id, this); - /** @type {Blockly.Connection} */ + /** @type {Connection} */ this.outputConnection = null; - /** @type {Blockly.Connection} */ + /** @type {Connection} */ this.nextConnection = null; - /** @type {Blockly.Connection} */ + /** @type {Connection} */ this.previousConnection = null; - /** @type {!Array} */ + /** @type {!Array} */ this.inputList = []; /** @type {boolean|undefined} */ this.inputsInline = undefined; @@ -88,19 +95,19 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { * @private */ this.disabled = false; - /** @type {!Blockly.Tooltip.TipInfo} */ + /** @type {!Tooltip.TipInfo} */ this.tooltip = ''; /** @type {boolean} */ this.contextMenu = true; /** - * @type {Blockly.Block} + * @type {Block} * @protected */ this.parentBlock_ = null; /** - * @type {!Array} + * @type {!Array} * @protected */ this.childBlocks_ = []; @@ -143,31 +150,27 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { /** * A string representing the comment attached to this block. - * @type {string|Blockly.Comment} + * @type {string|Comment} * @deprecated August 2019. Use getCommentText instead. */ this.comment = null; /** * A model of the comment attached to this block. - * @type {!Blockly.Block.CommentModel} + * @type {!Block.CommentModel} * @package */ - this.commentModel = { - text: null, - pinned: false, - size: new Blockly.utils.Size(160, 80) - }; + this.commentModel = {text: null, pinned: false, size: new Size(160, 80)}; /** * The block's position in workspace units. (0, 0) is at the workspace's * origin; scale does not change this value. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ - this.xy_ = new Blockly.utils.Coordinate(0, 0); + this.xy_ = new Coordinate(0, 0); - /** @type {!Blockly.Workspace} */ + /** @type {!Workspace} */ this.workspace = workspace; /** @type {boolean} */ this.isInFlyout = workspace.isFlyout; @@ -204,11 +207,11 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { if (prototypeName) { /** @type {string} */ this.type = prototypeName; - var prototype = Blockly.Blocks[prototypeName]; + const prototype = Blocks[prototypeName]; if (!prototype || typeof prototype != 'object') { throw TypeError('Unknown block type: ' + prototypeName); } - Blockly.utils.object.mixin(this, prototype); + object.mixin(this, prototype); } workspace.addTopBlock(this); @@ -217,32 +220,31 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { // All events fired should be part of the same group. // Any events fired during init should not be undoable, // so that block creation is atomic. - var existingGroup = Blockly.Events.getGroup(); + const existingGroup = Events.getGroup(); if (!existingGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } - var initialUndoFlag = Blockly.Events.recordUndo; + const initialUndoFlag = Events.recordUndo; try { // Call an initialization function, if it exists. if (typeof this.init == 'function') { - Blockly.Events.recordUndo = false; + Events.recordUndo = false; this.init(); - Blockly.Events.recordUndo = initialUndoFlag; + Events.recordUndo = initialUndoFlag; } // Fire a create event. - if (Blockly.Events.isEnabled()) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))( - this)); + if (Events.isEnabled()) { + Events.fire(new (Events.get(Events.BLOCK_CREATE))(this)); } } finally { if (!existingGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } // In case init threw, recordUndo flag should still be reset. - Blockly.Events.recordUndo = initialUndoFlag; + Events.recordUndo = initialUndoFlag; } // Record initial inline state. @@ -259,36 +261,36 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { * @typedef {{ * text:?string, * pinned:boolean, - * size:Blockly.utils.Size + * size:Size * }} */ -Blockly.Block.CommentModel; +Block.CommentModel; /** * The language-neutral ID given to the collapsed input. * @const {string} */ -Blockly.Block.COLLAPSED_INPUT_NAME = Blockly.constants.COLLAPSED_INPUT_NAME; +Block.COLLAPSED_INPUT_NAME = constants.COLLAPSED_INPUT_NAME; /** * The language-neutral ID given to the collapsed field. * @const {string} */ -Blockly.Block.COLLAPSED_FIELD_NAME = Blockly.constants.COLLAPSED_FIELD_NAME; +Block.COLLAPSED_FIELD_NAME = constants.COLLAPSED_FIELD_NAME; /** * Optional text data that round-trips between blocks and XML. * Has no effect. May be used by 3rd parties for meta information. * @type {?string} */ -Blockly.Block.prototype.data = null; +Block.prototype.data = null; /** * Has this block been disposed of? * @type {boolean} * @package */ -Blockly.Block.prototype.disposed = false; +Block.prototype.disposed = false; /** * Colour of the block as HSV hue value (0-360) @@ -296,56 +298,56 @@ Blockly.Block.prototype.disposed = false; * @type {?number} * @private */ -Blockly.Block.prototype.hue_ = null; +Block.prototype.hue_ = null; /** * Colour of the block in '#RRGGBB' format. * @type {string} * @protected */ -Blockly.Block.prototype.colour_ = '#000000'; +Block.prototype.colour_ = '#000000'; /** * Name of the block style. * @type {string} * @protected */ -Blockly.Block.prototype.styleName_ = ''; +Block.prototype.styleName_ = ''; /** * An optional method called during initialization. * @type {?function()} */ -Blockly.Block.prototype.init; +Block.prototype.init; /** * An optional callback method to use whenever the block's parent workspace * changes. This is usually only called from the constructor, the block type * initializer function, or an extension initializer function. - * @type {?function(Blockly.Events.Abstract)} + * @type {?function(Abstract)} */ -Blockly.Block.prototype.onchange; +Block.prototype.onchange; /** * An optional serialization method for defining how to serialize the * mutation state. This must be coupled with defining `domToMutation`. * @type {?function(...):!Element} */ -Blockly.Block.prototype.mutationToDom; +Block.prototype.mutationToDom; /** * An optional deserialization method for defining how to deserialize the * mutation state. This must be coupled with defining `mutationToDom`. * @type {?function(!Element)} */ -Blockly.Block.prototype.domToMutation; +Block.prototype.domToMutation; /** * An optional property for suppressing adding STATEMENT_PREFIX and * STATEMENT_SUFFIX to generated code. * @type {?boolean} */ -Blockly.Block.prototype.suppressPrefixSuffix; +Block.prototype.suppressPrefixSuffix; /** * An optional property for declaring developer variables. Return a list of @@ -353,7 +355,7 @@ Blockly.Block.prototype.suppressPrefixSuffix; * the user, but are declared as global variables in the generated code. * @type {?function():!Array} */ -Blockly.Block.prototype.getDeveloperVariables; +Block.prototype.getDeveloperVariables; /** * Dispose of this block. @@ -362,7 +364,7 @@ Blockly.Block.prototype.getDeveloperVariables; * all children of this block. * @suppress {checkTypes} */ -Blockly.Block.prototype.dispose = function(healStack) { +Block.prototype.dispose = function(healStack) { if (!this.workspace) { // Already deleted. return; @@ -373,11 +375,10 @@ Blockly.Block.prototype.dispose = function(healStack) { } this.unplug(healStack); - if (Blockly.Events.isEnabled()) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_DELETE))( - this)); + if (Events.isEnabled()) { + Events.fire(new (Events.get(Events.BLOCK_DELETE))(this)); } - Blockly.Events.disable(); + Events.disable(); try { // This block is now at the top of the workspace. @@ -399,22 +400,22 @@ Blockly.Block.prototype.dispose = function(healStack) { } // First, dispose of all my children. - for (var i = this.childBlocks_.length - 1; i >= 0; i--) { + for (let i = this.childBlocks_.length - 1; i >= 0; i--) { this.childBlocks_[i].dispose(false); } // Then dispose of myself. // Dispose of all inputs and their fields. - for (var i = 0, input; (input = this.inputList[i]); i++) { + for (let i = 0, input; (input = this.inputList[i]); i++) { input.dispose(); } this.inputList.length = 0; // Dispose of any remaining connections (next/previous/output). - var connections = this.getConnections_(true); - for (var i = 0, connection; (connection = connections[i]); i++) { + const connections = this.getConnections_(true); + for (let i = 0, connection; (connection = connections[i]); i++) { connection.dispose(); } } finally { - Blockly.Events.enable(); + Events.enable(); this.disposed = true; } }; @@ -428,9 +429,9 @@ Blockly.Block.prototype.dispose = function(healStack) { * change). * @public */ -Blockly.Block.prototype.initModel = function() { - for (var i = 0, input; (input = this.inputList[i]); i++) { - for (var j = 0, field; (field = input.fieldRow[j]); j++) { +Block.prototype.initModel = function() { + for (let i = 0, input; (input = this.inputList[i]); i++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { if (field.initModel) { field.initModel(); } @@ -444,7 +445,7 @@ Blockly.Block.prototype.initModel = function() { * @param {boolean=} opt_healStack Disconnect child statement and reconnect * stack. Defaults to false. */ -Blockly.Block.prototype.unplug = function(opt_healStack) { +Block.prototype.unplug = function(opt_healStack) { if (this.outputConnection) { this.unplugFromRow_(opt_healStack); } else if (this.previousConnection) { @@ -459,8 +460,8 @@ Blockly.Block.prototype.unplug = function(opt_healStack) { * left-side block. Defaults to false. * @private */ -Blockly.Block.prototype.unplugFromRow_ = function(opt_healStack) { - var parentConnection = null; +Block.prototype.unplugFromRow_ = function(opt_healStack) { + let parentConnection = null; if (this.outputConnection.isConnected()) { parentConnection = this.outputConnection.targetConnection; // Disconnect from any superior block. @@ -472,21 +473,20 @@ Blockly.Block.prototype.unplugFromRow_ = function(opt_healStack) { return; } - var thisConnection = this.getOnlyValueConnection_(); - if (!thisConnection || - !thisConnection.isConnected() || + const thisConnection = this.getOnlyValueConnection_(); + if (!thisConnection || !thisConnection.isConnected() || thisConnection.targetBlock().isShadow()) { // Too many or too few possible connections on this block, or there's // nothing on the other side of this connection. return; } - var childConnection = thisConnection.targetConnection; + const childConnection = thisConnection.targetConnection; // Disconnect the child block. childConnection.disconnect(); // Connect child to the parent if possible, otherwise bump away. if (this.workspace.connectionChecker.canConnect( - childConnection, parentConnection, false)) { + childConnection, parentConnection, false)) { parentConnection.connect(childConnection); } else { childConnection.onFailedConnect(parentConnection); @@ -500,15 +500,14 @@ Blockly.Block.prototype.unplugFromRow_ = function(opt_healStack) { * Since only one block can be displaced and attached to the insertion marker * this should only ever return one connection. * - * @return {?Blockly.Connection} The connection on the value input, or null. + * @return {?Connection} The connection on the value input, or null. * @private */ -Blockly.Block.prototype.getOnlyValueConnection_ = function() { - var connection = null; - for (var i = 0; i < this.inputList.length; i++) { - var thisConnection = this.inputList[i].connection; - if (thisConnection && - thisConnection.type == Blockly.connectionTypes.INPUT_VALUE && +Block.prototype.getOnlyValueConnection_ = function() { + let connection = null; + for (let i = 0; i < this.inputList.length; i++) { + const thisConnection = this.inputList[i].connection; + if (thisConnection && thisConnection.type == connectionTypes.INPUT_VALUE && thisConnection.targetConnection) { if (connection) { return null; // More than one value input found. @@ -526,18 +525,18 @@ Blockly.Block.prototype.getOnlyValueConnection_ = function() { * stack. Defaults to false. * @private */ -Blockly.Block.prototype.unplugFromStack_ = function(opt_healStack) { - var previousTarget = null; +Block.prototype.unplugFromStack_ = function(opt_healStack) { + let previousTarget = null; if (this.previousConnection.isConnected()) { // Remember the connection that any next statements need to connect to. previousTarget = this.previousConnection.targetConnection; // Detach this block from the parent's tree. this.previousConnection.disconnect(); } - var nextBlock = this.getNextBlock(); + const nextBlock = this.getNextBlock(); if (opt_healStack && nextBlock && !nextBlock.isShadow()) { // Disconnect the next statement. - var nextTarget = this.nextConnection.targetConnection; + const nextTarget = this.nextConnection.targetConnection; nextTarget.disconnect(); if (previousTarget && this.workspace.connectionChecker.canConnect( @@ -551,11 +550,11 @@ Blockly.Block.prototype.unplugFromStack_ = function(opt_healStack) { /** * Returns all connections originating from this block. * @param {boolean} _all If true, return all connections even hidden ones. - * @return {!Array} Array of connections. + * @return {!Array} Array of connections. * @package */ -Blockly.Block.prototype.getConnections_ = function(_all) { - var myConnections = []; +Block.prototype.getConnections_ = function(_all) { + const myConnections = []; if (this.outputConnection) { myConnections.push(this.outputConnection); } @@ -565,7 +564,7 @@ Blockly.Block.prototype.getConnections_ = function(_all) { if (this.nextConnection) { myConnections.push(this.nextConnection); } - for (var i = 0, input; (input = this.inputList[i]); i++) { + for (let i = 0, input; (input = this.inputList[i]); i++) { if (input.connection) { myConnections.push(input.connection); } @@ -578,13 +577,13 @@ Blockly.Block.prototype.getConnections_ = function(_all) { * @param {boolean} ignoreShadows If true,the last connection on a non-shadow * block will be returned. If false, this will follow shadows to find the * last connection. - * @return {?Blockly.Connection} The last next connection on the stack, or null. + * @return {?Connection} The last next connection on the stack, or null. * @package */ -Blockly.Block.prototype.lastConnectionInStack = function(ignoreShadows) { - var nextConnection = this.nextConnection; +Block.prototype.lastConnectionInStack = function(ignoreShadows) { + let nextConnection = this.nextConnection; while (nextConnection) { - var nextBlock = nextConnection.targetBlock(); + const nextBlock = nextConnection.targetBlock(); if (!nextBlock || (ignoreShadows && nextBlock.isShadow())) { return nextConnection; } @@ -597,28 +596,29 @@ Blockly.Block.prototype.lastConnectionInStack = function(ignoreShadows) { * Bump unconnected blocks out of alignment. Two blocks which aren't actually * connected should not coincidentally line up on screen. */ -Blockly.Block.prototype.bumpNeighbours = function() { +Block.prototype.bumpNeighbours = function() { // noop. }; /** * Return the parent block or null if this block is at the top level. The parent - * block is either the block connected to the previous connection (for a statement - * block) or the block connected to the output connection (for a value block). - * @return {?Blockly.Block} The block (if any) that holds the current block. + * block is either the block connected to the previous connection (for a + * statement block) or the block connected to the output connection (for a value + * block). + * @return {?Block} The block (if any) that holds the current block. */ -Blockly.Block.prototype.getParent = function() { +Block.prototype.getParent = function() { return this.parentBlock_; }; /** * Return the input that connects to the specified block. - * @param {!Blockly.Block} block A block connected to an input on this block. - * @return {?Blockly.Input} The input (if any) that connects to the specified + * @param {!Block} block A block connected to an input on this block. + * @return {?Input} The input (if any) that connects to the specified * block. */ -Blockly.Block.prototype.getInputWithBlock = function(block) { - for (var i = 0, input; (input = this.inputList[i]); i++) { +Block.prototype.getInputWithBlock = function(block) { + for (let i = 0, input; (input = this.inputList[i]); i++) { if (input.connection && input.connection.targetBlock() == block) { return input; } @@ -630,12 +630,13 @@ Blockly.Block.prototype.getInputWithBlock = function(block) { * Return the parent block that surrounds the current block, or null if this * block has no surrounding block. A parent block might just be the previous * statement, whereas the surrounding block is an if statement, while loop, etc. - * @return {?Blockly.Block} The block (if any) that surrounds the current block. + * @return {?Block} The block (if any) that surrounds the current block. */ -Blockly.Block.prototype.getSurroundParent = function() { - var block = this; +Block.prototype.getSurroundParent = function() { + let block = this; + let prevBlock; do { - var prevBlock = block; + prevBlock = block; block = block.getParent(); if (!block) { // Ran off the top. @@ -648,30 +649,30 @@ Blockly.Block.prototype.getSurroundParent = function() { /** * Return the next statement block directly connected to this block. - * @return {?Blockly.Block} The next statement block or null. + * @return {?Block} The next statement block or null. */ -Blockly.Block.prototype.getNextBlock = function() { +Block.prototype.getNextBlock = function() { return this.nextConnection && this.nextConnection.targetBlock(); }; /** * Returns the block connected to the previous connection. - * @return {?Blockly.Block} The previous statement block or null. + * @return {?Block} The previous statement block or null. */ -Blockly.Block.prototype.getPreviousBlock = function() { +Block.prototype.getPreviousBlock = function() { return this.previousConnection && this.previousConnection.targetBlock(); }; /** * Return the connection on the first statement input on this block, or null if * there are none. - * @return {?Blockly.Connection} The first statement connection or null. + * @return {?Connection} The first statement connection or null. * @package */ -Blockly.Block.prototype.getFirstStatementConnection = function() { - for (var i = 0, input; (input = this.inputList[i]); i++) { +Block.prototype.getFirstStatementConnection = function() { + for (let i = 0, input; (input = this.inputList[i]); i++) { if (input.connection && - input.connection.type == Blockly.connectionTypes.NEXT_STATEMENT) { + input.connection.type == connectionTypes.NEXT_STATEMENT) { return input.connection; } } @@ -681,11 +682,11 @@ Blockly.Block.prototype.getFirstStatementConnection = function() { /** * Return the top-most block in this block's tree. * This will return itself if this block is at the top level. - * @return {!Blockly.Block} The root block. + * @return {!Block} The root block. */ -Blockly.Block.prototype.getRootBlock = function() { - var rootBlock; - var block = this; +Block.prototype.getRootBlock = function() { + let rootBlock; + let block = this; do { rootBlock = block; block = rootBlock.parentBlock_; @@ -697,13 +698,14 @@ Blockly.Block.prototype.getRootBlock = function() { * Walk up from the given block up through the stack of blocks to find * the top block of the sub stack. If we are nested in a statement input only * find the top-most nested block. Do not go all the way to the root block. - * @return {!Blockly.Block} The top block in a stack. + * @return {!Block} The top block in a stack. * @package */ -Blockly.Block.prototype.getTopStackBlock = function() { - var block = this; +Block.prototype.getTopStackBlock = function() { + let block = this; + let previous; do { - var previous = block.getPreviousBlock(); + previous = block.getPreviousBlock(); } while (previous && previous.getNextBlock() == block && (block = previous)); return block; }; @@ -714,22 +716,22 @@ Blockly.Block.prototype.getTopStackBlock = function() { * Excludes any connection on an output tab or any preceding statement. * Blocks are optionally sorted by position; top to bottom. * @param {boolean} ordered Sort the list if true. - * @return {!Array} Array of blocks. + * @return {!Array} Array of blocks. */ -Blockly.Block.prototype.getChildren = function(ordered) { +Block.prototype.getChildren = function(ordered) { if (!ordered) { return this.childBlocks_; } - var blocks = []; - for (var i = 0, input; (input = this.inputList[i]); i++) { + const blocks = []; + for (let i = 0, input; (input = this.inputList[i]); i++) { if (input.connection) { - var child = input.connection.targetBlock(); + const child = input.connection.targetBlock(); if (child) { blocks.push(child); } } } - var next = this.getNextBlock(); + const next = this.getNextBlock(); if (next) { blocks.push(next); } @@ -738,31 +740,32 @@ Blockly.Block.prototype.getChildren = function(ordered) { /** * Set parent of this block to be a new block or null. - * @param {Blockly.Block} newParent New parent block. + * @param {Block} newParent New parent block. * @package */ -Blockly.Block.prototype.setParent = function(newParent) { +Block.prototype.setParent = function(newParent) { if (newParent === this.parentBlock_) { return; } // Check that block is connected to new parent if new parent is not null and // that block is not connected to superior one if new parent is null. - var connection = this.previousConnection || this.outputConnection; - var isConnected = !!(connection && connection.targetBlock()); + const connection = this.previousConnection || this.outputConnection; + const isConnected = !!(connection && connection.targetBlock()); if (isConnected && newParent && connection.targetBlock() !== newParent) { throw Error('Block connected to superior one that is not new parent.'); } else if (!isConnected && newParent) { throw Error('Block not connected to new parent.'); } else if (isConnected && !newParent) { - throw Error('Cannot set parent to null while block is still connected to' + + throw Error( + 'Cannot set parent to null while block is still connected to' + ' superior block.'); } if (this.parentBlock_) { // Remove this block from the old parent's child list. - Blockly.utils.arrayRemove(this.parentBlock_.childBlocks_, this); + utils.arrayRemove(this.parentBlock_.childBlocks_, this); // This block hasn't actually moved on-screen, so there's no need to update // its connection locations. @@ -788,12 +791,12 @@ Blockly.Block.prototype.setParent = function(newParent) { * Excludes any connection on an output tab or any preceding statements. * Blocks are optionally sorted by position; top to bottom. * @param {boolean} ordered Sort the list if true. - * @return {!Array} Flattened array of blocks. + * @return {!Array} Flattened array of blocks. */ -Blockly.Block.prototype.getDescendants = function(ordered) { - var blocks = [this]; - var childBlocks = this.getChildren(ordered); - for (var child, i = 0; (child = childBlocks[i]); i++) { +Block.prototype.getDescendants = function(ordered) { + const blocks = [this]; + const childBlocks = this.getChildren(ordered); + for (let child, i = 0; (child = childBlocks[i]); i++) { blocks.push.apply(blocks, child.getDescendants(ordered)); } return blocks; @@ -803,7 +806,7 @@ Blockly.Block.prototype.getDescendants = function(ordered) { * Get whether this block is deletable or not. * @return {boolean} True if deletable. */ -Blockly.Block.prototype.isDeletable = function() { +Block.prototype.isDeletable = function() { return this.deletable_ && !this.isShadow_ && !(this.workspace && this.workspace.options.readOnly); }; @@ -812,7 +815,7 @@ Blockly.Block.prototype.isDeletable = function() { * Set whether this block is deletable or not. * @param {boolean} deletable True if deletable. */ -Blockly.Block.prototype.setDeletable = function(deletable) { +Block.prototype.setDeletable = function(deletable) { this.deletable_ = deletable; }; @@ -820,7 +823,7 @@ Blockly.Block.prototype.setDeletable = function(deletable) { * Get whether this block is movable or not. * @return {boolean} True if movable. */ -Blockly.Block.prototype.isMovable = function() { +Block.prototype.isMovable = function() { return this.movable_ && !this.isShadow_ && !(this.workspace && this.workspace.options.readOnly); }; @@ -829,7 +832,7 @@ Blockly.Block.prototype.isMovable = function() { * Set whether this block is movable or not. * @param {boolean} movable True if movable. */ -Blockly.Block.prototype.setMovable = function(movable) { +Block.prototype.setMovable = function(movable) { this.movable_ = movable; }; @@ -840,19 +843,19 @@ Blockly.Block.prototype.setMovable = function(movable) { * type over their maxInstances this block is not duplicatable. * @return {boolean} True if duplicatable. */ -Blockly.Block.prototype.isDuplicatable = function() { +Block.prototype.isDuplicatable = function() { if (!this.workspace.hasBlockLimits()) { return true; } return this.workspace.isCapacityAvailable( - Blockly.utils.getBlockTypeCounts(this, true)); + utils.getBlockTypeCounts(this, true)); }; /** * Get whether this block is a shadow block or not. * @return {boolean} True if a shadow. */ -Blockly.Block.prototype.isShadow = function() { +Block.prototype.isShadow = function() { return this.isShadow_; }; @@ -861,7 +864,7 @@ Blockly.Block.prototype.isShadow = function() { * @param {boolean} shadow True if a shadow. * @package */ -Blockly.Block.prototype.setShadow = function(shadow) { +Block.prototype.setShadow = function(shadow) { this.isShadow_ = shadow; }; @@ -869,7 +872,7 @@ Blockly.Block.prototype.setShadow = function(shadow) { * Get whether this block is an insertion marker block or not. * @return {boolean} True if an insertion marker. */ -Blockly.Block.prototype.isInsertionMarker = function() { +Block.prototype.isInsertionMarker = function() { return this.isInsertionMarker_; }; @@ -879,7 +882,7 @@ Blockly.Block.prototype.isInsertionMarker = function() { * @param {boolean} insertionMarker True if an insertion marker. * @package */ -Blockly.Block.prototype.setInsertionMarker = function(insertionMarker) { +Block.prototype.setInsertionMarker = function(insertionMarker) { this.isInsertionMarker_ = insertionMarker; }; @@ -887,7 +890,7 @@ Blockly.Block.prototype.setInsertionMarker = function(insertionMarker) { * Get whether this block is editable or not. * @return {boolean} True if editable. */ -Blockly.Block.prototype.isEditable = function() { +Block.prototype.isEditable = function() { return this.editable_ && !(this.workspace && this.workspace.options.readOnly); }; @@ -895,10 +898,10 @@ Blockly.Block.prototype.isEditable = function() { * Set whether this block is editable or not. * @param {boolean} editable True if editable. */ -Blockly.Block.prototype.setEditable = function(editable) { +Block.prototype.setEditable = function(editable) { this.editable_ = editable; - for (var i = 0, input; (input = this.inputList[i]); i++) { - for (var j = 0, field; (field = input.fieldRow[j]); j++) { + for (let i = 0, input; (input = this.inputList[i]); i++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { field.updateEditable(); } } @@ -908,7 +911,7 @@ Blockly.Block.prototype.setEditable = function(editable) { * Returns if this block has been disposed of / deleted. * @return {boolean} True if this block has been disposed of / deleted. */ -Blockly.Block.prototype.isDisposed = function() { +Block.prototype.isDisposed = function() { return this.disposed; }; @@ -916,18 +919,18 @@ Blockly.Block.prototype.isDisposed = function() { * Find the connection on this block that corresponds to the given connection * on the other block. * Used to match connections between a block and its insertion marker. - * @param {!Blockly.Block} otherBlock The other block to match against. - * @param {!Blockly.Connection} conn The other connection to match. - * @return {?Blockly.Connection} The matching connection on this block, or null. + * @param {!Block} otherBlock The other block to match against. + * @param {!Connection} conn The other connection to match. + * @return {?Connection} The matching connection on this block, or null. * @package */ -Blockly.Block.prototype.getMatchingConnection = function(otherBlock, conn) { - var connections = this.getConnections_(true); - var otherConnections = otherBlock.getConnections_(true); +Block.prototype.getMatchingConnection = function(otherBlock, conn) { + const connections = this.getConnections_(true); + const otherConnections = otherBlock.getConnections_(true); if (connections.length != otherConnections.length) { - throw Error("Connection lists did not match in length."); + throw Error('Connection lists did not match in length.'); } - for (var i = 0; i < otherConnections.length; i++) { + for (let i = 0; i < otherConnections.length; i++) { if (otherConnections[i] == conn) { return connections[i]; } @@ -940,17 +943,17 @@ Blockly.Block.prototype.getMatchingConnection = function(otherBlock, conn) { * @param {string|Function} url URL string for block help, or function that * returns a URL. Null for no help. */ -Blockly.Block.prototype.setHelpUrl = function(url) { +Block.prototype.setHelpUrl = function(url) { this.helpUrl = url; }; /** * Sets the tooltip for this block. - * @param {!Blockly.Tooltip.TipInfo} newTip The text for the tooltip, a function + * @param {!Tooltip.TipInfo} newTip The text for the tooltip, a function * that returns the text for the tooltip, or a parent object whose tooltip * will be used. To not display a tooltip pass the empty string. */ -Blockly.Block.prototype.setTooltip = function(newTip) { +Block.prototype.setTooltip = function(newTip) { this.tooltip = newTip; }; @@ -958,15 +961,15 @@ Blockly.Block.prototype.setTooltip = function(newTip) { * Returns the tooltip text for this block. * @return {!string} The tooltip text for this block. */ -Blockly.Block.prototype.getTooltip = function() { - return Blockly.Tooltip.getTooltipOfObject(this); +Block.prototype.getTooltip = function() { + return Tooltip.getTooltipOfObject(this); }; /** * Get the colour of a block. * @return {string} #RRGGBB string. */ -Blockly.Block.prototype.getColour = function() { +Block.prototype.getColour = function() { return this.colour_; }; @@ -974,7 +977,7 @@ Blockly.Block.prototype.getColour = function() { * Get the name of the block style. * @return {string} Name of the block style. */ -Blockly.Block.prototype.getStyleName = function() { +Block.prototype.getStyleName = function() { return this.styleName_; }; @@ -982,7 +985,7 @@ Blockly.Block.prototype.getStyleName = function() { * Get the HSV hue value of a block. Null if hue not set. * @return {?number} Hue value (0-360). */ -Blockly.Block.prototype.getHue = function() { +Block.prototype.getHue = function() { return this.hue_; }; @@ -991,8 +994,8 @@ Blockly.Block.prototype.getHue = function() { * @param {number|string} colour HSV hue value (0 to 360), #RRGGBB string, * or a message reference string pointing to one of those two values. */ -Blockly.Block.prototype.setColour = function(colour) { - var parsed = Blockly.utils.parseBlockColour(colour); +Block.prototype.setColour = function(colour) { + const parsed = utils.parseBlockColour(colour); this.hue_ = parsed.hue; this.colour_ = parsed.hex; }; @@ -1001,7 +1004,7 @@ Blockly.Block.prototype.setColour = function(colour) { * Set the style and colour values of a block. * @param {string} blockStyleName Name of the block style. */ -Blockly.Block.prototype.setStyle = function(blockStyleName) { +Block.prototype.setStyle = function(blockStyleName) { this.styleName_ = blockStyleName; }; @@ -1010,11 +1013,11 @@ Blockly.Block.prototype.setStyle = function(blockStyleName) { * changes, replacing any prior onchange handler. This is usually only called * from the constructor, the block type initializer function, or an extension * initializer function. - * @param {function(Blockly.Events.Abstract)} onchangeFn The callback to call + * @param {function(Abstract)} onchangeFn The callback to call * when the block's workspace changes. * @throws {Error} if onchangeFn is not falsey and not a function. */ -Blockly.Block.prototype.setOnChange = function(onchangeFn) { +Block.prototype.setOnChange = function(onchangeFn) { if (onchangeFn && typeof onchangeFn != 'function') { throw Error('onchange must be a function.'); } @@ -1031,17 +1034,18 @@ Blockly.Block.prototype.setOnChange = function(onchangeFn) { /** * Returns the named field from a block. * @param {string} name The name of the field. - * @return {?Blockly.Field} Named field, or null if field does not exist. + * @return {?Field} Named field, or null if field does not exist. */ -Blockly.Block.prototype.getField = function(name) { +Block.prototype.getField = function(name) { if (typeof name !== 'string') { - throw TypeError('Blockly.Block.prototype.getField expects a string ' + - 'with the field name but received ' + - (name === undefined ? 'nothing' : name + ' of type ' + typeof name) + - ' instead'); + throw TypeError( + 'Block.prototype.getField expects a string ' + + 'with the field name but received ' + + (name === undefined ? 'nothing' : name + ' of type ' + typeof name) + + ' instead'); } - for (var i = 0, input; (input = this.inputList[i]); i++) { - for (var j = 0, field; (field = input.fieldRow[j]); j++) { + for (let i = 0, input; (input = this.inputList[i]); i++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { if (field.name === name) { return field; } @@ -1054,10 +1058,10 @@ Blockly.Block.prototype.getField = function(name) { * Return all variables referenced by this block. * @return {!Array} List of variable names. */ -Blockly.Block.prototype.getVars = function() { - var vars = []; - for (var i = 0, input; (input = this.inputList[i]); i++) { - for (var j = 0, field; (field = input.fieldRow[j]); j++) { +Block.prototype.getVars = function() { + const vars = []; + for (let i = 0, input; (input = this.inputList[i]); i++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { if (field.referencesVariables()) { vars.push(field.getValue()); } @@ -1068,15 +1072,15 @@ Blockly.Block.prototype.getVars = function() { /** * Return all variables referenced by this block. - * @return {!Array} List of variable models. + * @return {!Array} List of variable models. * @package */ -Blockly.Block.prototype.getVarModels = function() { - var vars = []; - for (var i = 0, input; (input = this.inputList[i]); i++) { - for (var j = 0, field; (field = input.fieldRow[j]); j++) { +Block.prototype.getVarModels = function() { + const vars = []; + for (let i = 0, input; (input = this.inputList[i]); i++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { if (field.referencesVariables()) { - var model = this.workspace.getVariableById( + const model = this.workspace.getVariableById( /** @type {string} */ (field.getValue())); // Check if the variable actually exists (and isn't just a potential // variable). @@ -1092,14 +1096,13 @@ Blockly.Block.prototype.getVarModels = function() { /** * Notification that a variable is renaming but keeping the same ID. If the * variable is in use on this block, rerender to show the new name. - * @param {!Blockly.VariableModel} variable The variable being renamed. + * @param {!VariableModel} variable The variable being renamed. * @package */ -Blockly.Block.prototype.updateVarName = function(variable) { - for (var i = 0, input; (input = this.inputList[i]); i++) { - for (var j = 0, field; (field = input.fieldRow[j]); j++) { - if (field.referencesVariables() && - variable.getId() == field.getValue()) { +Block.prototype.updateVarName = function(variable) { + for (let i = 0, input; (input = this.inputList[i]); i++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { + if (field.referencesVariables() && variable.getId() == field.getValue()) { field.refreshVariableName(); } } @@ -1113,11 +1116,10 @@ Blockly.Block.prototype.updateVarName = function(variable) { * @param {string} newId ID of new variable. May be the same as oldId, but with * an updated name. */ -Blockly.Block.prototype.renameVarById = function(oldId, newId) { - for (var i = 0, input; (input = this.inputList[i]); i++) { - for (var j = 0, field; (field = input.fieldRow[j]); j++) { - if (field.referencesVariables() && - oldId == field.getValue()) { +Block.prototype.renameVarById = function(oldId, newId) { + for (let i = 0, input; (input = this.inputList[i]); i++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { + if (field.referencesVariables() && oldId == field.getValue()) { field.setValue(newId); } } @@ -1129,8 +1131,8 @@ Blockly.Block.prototype.renameVarById = function(oldId, newId) { * @param {string} name The name of the field. * @return {*} Value of the field or null if field does not exist. */ -Blockly.Block.prototype.getFieldValue = function(name) { - var field = this.getField(name); +Block.prototype.getFieldValue = function(name) { + const field = this.getField(name); if (field) { return field.getValue(); } @@ -1142,8 +1144,8 @@ Blockly.Block.prototype.getFieldValue = function(name) { * @param {*} newValue The value to set. * @param {string} name The name of the field to set the value of. */ -Blockly.Block.prototype.setFieldValue = function(newValue, name) { - var field = this.getField(name); +Block.prototype.setFieldValue = function(newValue, name) { + const field = this.getField(name); if (!field) { throw Error('Field "' + name + '" not found.'); } @@ -1156,24 +1158,26 @@ Blockly.Block.prototype.setFieldValue = function(newValue, name) { * @param {(string|Array|null)=} opt_check Statement type or * list of statement types. Null/undefined if any type could be connected. */ -Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) { +Block.prototype.setPreviousStatement = function(newBoolean, opt_check) { if (newBoolean) { if (opt_check === undefined) { opt_check = null; } if (!this.previousConnection) { if (this.outputConnection) { - throw Error('Remove output connection prior to adding previous ' + + throw Error( + 'Remove output connection prior to adding previous ' + 'connection.'); } this.previousConnection = - this.makeConnection_(Blockly.connectionTypes.PREVIOUS_STATEMENT); + this.makeConnection_(connectionTypes.PREVIOUS_STATEMENT); } this.previousConnection.setCheck(opt_check); } else { if (this.previousConnection) { if (this.previousConnection.isConnected()) { - throw Error('Must disconnect previous statement before removing ' + + throw Error( + 'Must disconnect previous statement before removing ' + 'connection.'); } this.previousConnection.dispose(); @@ -1188,20 +1192,21 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) { * @param {(string|Array|null)=} opt_check Statement type or * list of statement types. Null/undefined if any type could be connected. */ -Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) { +Block.prototype.setNextStatement = function(newBoolean, opt_check) { if (newBoolean) { if (opt_check === undefined) { opt_check = null; } if (!this.nextConnection) { this.nextConnection = - this.makeConnection_(Blockly.connectionTypes.NEXT_STATEMENT); + this.makeConnection_(connectionTypes.NEXT_STATEMENT); } this.nextConnection.setCheck(opt_check); } else { if (this.nextConnection) { if (this.nextConnection.isConnected()) { - throw Error('Must disconnect next statement before removing ' + + throw Error( + 'Must disconnect next statement before removing ' + 'connection.'); } this.nextConnection.dispose(); @@ -1217,18 +1222,19 @@ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) { * of returned types. Null or undefined if any type could be returned * (e.g. variable get). */ -Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) { +Block.prototype.setOutput = function(newBoolean, opt_check) { if (newBoolean) { if (opt_check === undefined) { opt_check = null; } if (!this.outputConnection) { if (this.previousConnection) { - throw Error('Remove previous connection prior to adding output ' + + throw Error( + 'Remove previous connection prior to adding output ' + 'connection.'); } this.outputConnection = - this.makeConnection_(Blockly.connectionTypes.OUTPUT_VALUE); + this.makeConnection_(connectionTypes.OUTPUT_VALUE); } this.outputConnection.setCheck(opt_check); } else { @@ -1246,9 +1252,9 @@ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) { * Set whether value inputs are arranged horizontally or vertically. * @param {boolean} newBoolean True if inputs are horizontal. */ -Blockly.Block.prototype.setInputsInline = function(newBoolean) { +Block.prototype.setInputsInline = function(newBoolean) { if (this.inputsInline != newBoolean) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this, 'inline', null, this.inputsInline, newBoolean)); this.inputsInline = newBoolean; } @@ -1258,22 +1264,22 @@ Blockly.Block.prototype.setInputsInline = function(newBoolean) { * Get whether value inputs are arranged horizontally or vertically. * @return {boolean} True if inputs are horizontal. */ -Blockly.Block.prototype.getInputsInline = function() { +Block.prototype.getInputsInline = function() { if (this.inputsInline != undefined) { // Set explicitly. return this.inputsInline; } // Not defined explicitly. Figure out what would look best. - for (var i = 1; i < this.inputList.length; i++) { - if (this.inputList[i - 1].type == Blockly.inputTypes.DUMMY && - this.inputList[i].type == Blockly.inputTypes.DUMMY) { + for (let i = 1; i < this.inputList.length; i++) { + if (this.inputList[i - 1].type == inputTypes.DUMMY && + this.inputList[i].type == inputTypes.DUMMY) { // Two dummy inputs in a row. Don't inline them. return false; } } - for (var i = 1; i < this.inputList.length; i++) { - if (this.inputList[i - 1].type == Blockly.inputTypes.VALUE && - this.inputList[i].type == Blockly.inputTypes.DUMMY) { + for (let i = 1; i < this.inputList.length; i++) { + if (this.inputList[i - 1].type == inputTypes.VALUE && + this.inputList[i].type == inputTypes.DUMMY) { // Dummy input after a value input. Inline them. return true; } @@ -1285,7 +1291,7 @@ Blockly.Block.prototype.getInputsInline = function() { * Set the block's output shape. * @param {?number} outputShape Value representing an output shape. */ -Blockly.Block.prototype.setOutputShape = function(outputShape) { +Block.prototype.setOutputShape = function(outputShape) { this.outputShape_ = outputShape; }; @@ -1293,7 +1299,7 @@ Blockly.Block.prototype.setOutputShape = function(outputShape) { * Get the block's output shape. * @return {?number} Value representing output shape if one exists. */ -Blockly.Block.prototype.getOutputShape = function() { +Block.prototype.getOutputShape = function() { return this.outputShape_; }; @@ -1301,7 +1307,7 @@ Blockly.Block.prototype.getOutputShape = function() { * Get whether this block is enabled or not. * @return {boolean} True if enabled. */ -Blockly.Block.prototype.isEnabled = function() { +Block.prototype.isEnabled = function() { return !this.disabled; }; @@ -1309,9 +1315,9 @@ Blockly.Block.prototype.isEnabled = function() { * Set whether the block is enabled or not. * @param {boolean} enabled True if enabled. */ -Blockly.Block.prototype.setEnabled = function(enabled) { +Block.prototype.setEnabled = function(enabled) { if (this.isEnabled() != enabled) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this, 'disabled', null, this.disabled, !enabled)); this.disabled = !enabled; } @@ -1322,8 +1328,8 @@ Blockly.Block.prototype.setEnabled = function(enabled) { * The block's own disabled property is not considered. * @return {boolean} True if disabled. */ -Blockly.Block.prototype.getInheritedDisabled = function() { - var ancestor = this.getSurroundParent(); +Block.prototype.getInheritedDisabled = function() { + let ancestor = this.getSurroundParent(); while (ancestor) { if (ancestor.disabled) { return true; @@ -1338,7 +1344,7 @@ Blockly.Block.prototype.getInheritedDisabled = function() { * Get whether the block is collapsed or not. * @return {boolean} True if collapsed. */ -Blockly.Block.prototype.isCollapsed = function() { +Block.prototype.isCollapsed = function() { return this.collapsed_; }; @@ -1346,9 +1352,9 @@ Blockly.Block.prototype.isCollapsed = function() { * Set whether the block is collapsed or not. * @param {boolean} collapsed True if collapsed. */ -Blockly.Block.prototype.setCollapsed = function(collapsed) { +Block.prototype.setCollapsed = function(collapsed) { if (this.collapsed_ != collapsed) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this, 'collapsed', null, this.collapsed_, collapsed)); this.collapsed_ = collapsed; } @@ -1361,29 +1367,29 @@ Blockly.Block.prototype.setCollapsed = function(collapsed) { * empty field. If not specified, '?' is used. * @return {string} Text of block. */ -Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { - var text = []; - var emptyFieldPlaceholder = opt_emptyToken || '?'; +Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { + let text = []; + const emptyFieldPlaceholder = opt_emptyToken || '?'; // Temporarily set flag to navigate to all fields. - var prevNavigateFields = Blockly.ASTNode.NAVIGATE_ALL_FIELDS; - Blockly.ASTNode.NAVIGATE_ALL_FIELDS = true; + const prevNavigateFields = ASTNode.NAVIGATE_ALL_FIELDS; + ASTNode.NAVIGATE_ALL_FIELDS = true; - var node = Blockly.ASTNode.createBlockNode(this); - var rootNode = node; + let node = ASTNode.createBlockNode(this); + const rootNode = node; /** * Whether or not to add parentheses around an input. - * @param {!Blockly.Connection} connection The connection. + * @param {!Connection} connection The connection. * @return {boolean} True if we should add parentheses around the input. */ function shouldAddParentheses(connection) { - var checks = connection.getCheck(); + let checks = connection.getCheck(); if (!checks && connection.targetConnection) { checks = connection.targetConnection.getCheck(); } - return !!checks && (checks.indexOf('Boolean') != -1 || - checks.indexOf('Number') != -1); + return !!checks && + (checks.indexOf('Boolean') != -1 || checks.indexOf('Number') != -1); } /** @@ -1399,23 +1405,25 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { // Traverse the AST building up our text string. while (node) { switch (node.getType()) { - case Blockly.ASTNode.types.INPUT: - var connection = /** @type {!Blockly.Connection} */ (node.getLocation()); + case ASTNode.types.INPUT: { + const connection = /** @type {!Connection} */ (node.getLocation()); if (!node.in()) { text.push(emptyFieldPlaceholder); } else if (shouldAddParentheses(connection)) { text.push('('); } break; - case Blockly.ASTNode.types.FIELD: - var field = /** @type {Blockly.Field} */ (node.getLocation()); - if (field.name != Blockly.constants.COLLAPSED_FIELD_NAME) { + } + case ASTNode.types.FIELD: { + const field = /** @type {Field} */ (node.getLocation()); + if (field.name != constants.COLLAPSED_FIELD_NAME) { text.push(field.getText()); } break; + } } - var current = node; + const current = node; node = current.in() || current.next(); if (!node) { // Can't go in or next, keep going out until we can go next. @@ -1425,9 +1433,9 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { node = node.out(); checkRoot(); // If we hit an input on the way up, possibly close out parentheses. - if (node && node.getType() == Blockly.ASTNode.types.INPUT && + if (node && node.getType() == ASTNode.types.INPUT && shouldAddParentheses( - /** @type {!Blockly.Connection} */ (node.getLocation()))) { + /** @type {!Connection} */ (node.getLocation()))) { text.push(')'); } } @@ -1438,12 +1446,12 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { } // Restore state of NAVIGATE_ALL_FIELDS. - Blockly.ASTNode.NAVIGATE_ALL_FIELDS = prevNavigateFields; + ASTNode.NAVIGATE_ALL_FIELDS = prevNavigateFields; // Run through our text array and simplify expression to remove parentheses // around single field blocks. // E.g. ['repeat', '(', '10', ')', 'times', 'do', '?'] - for (var i = 2; i < text.length; i++) { + for (let i = 2; i < text.length; i++) { if (text[i - 2] == '(' && text[i] == ')') { text[i - 2] = text[i - 1]; text.splice(i - 1, 2); @@ -1470,30 +1478,30 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { * Shortcut for appending a value input row. * @param {string} name Language-neutral identifier which may used to find this * input again. Should be unique to this block. - * @return {!Blockly.Input} The input object created. + * @return {!Input} The input object created. */ -Blockly.Block.prototype.appendValueInput = function(name) { - return this.appendInput_(Blockly.inputTypes.VALUE, name); +Block.prototype.appendValueInput = function(name) { + return this.appendInput_(inputTypes.VALUE, name); }; /** * Shortcut for appending a statement input row. * @param {string} name Language-neutral identifier which may used to find this * input again. Should be unique to this block. - * @return {!Blockly.Input} The input object created. + * @return {!Input} The input object created. */ -Blockly.Block.prototype.appendStatementInput = function(name) { - return this.appendInput_(Blockly.inputTypes.STATEMENT, name); +Block.prototype.appendStatementInput = function(name) { + return this.appendInput_(inputTypes.STATEMENT, name); }; /** * Shortcut for appending a dummy input row. * @param {string=} opt_name Language-neutral identifier which may used to find * this input again. Should be unique to this block. - * @return {!Blockly.Input} The input object created. + * @return {!Input} The input object created. */ -Blockly.Block.prototype.appendDummyInput = function(opt_name) { - return this.appendInput_(Blockly.inputTypes.DUMMY, opt_name || ''); +Block.prototype.appendDummyInput = function(opt_name) { + return this.appendInput_(inputTypes.DUMMY, opt_name || ''); }; /** @@ -1501,12 +1509,13 @@ Blockly.Block.prototype.appendDummyInput = function(opt_name) { * JSON description. * @param {!Object} json Structured data describing the block. */ -Blockly.Block.prototype.jsonInit = function(json) { - var warningPrefix = json['type'] ? 'Block "' + json['type'] + '": ' : ''; +Block.prototype.jsonInit = function(json) { + const warningPrefix = json['type'] ? 'Block "' + json['type'] + '": ' : ''; // Validate inputs. if (json['output'] && json['previousStatement']) { - throw Error(warningPrefix + + throw Error( + warningPrefix + 'Must not have both an output and a previousStatement.'); } @@ -1527,10 +1536,11 @@ Blockly.Block.prototype.jsonInit = function(json) { } // Interpolate the message blocks. - var i = 0; + let i = 0; while (json['message' + i] !== undefined) { - this.interpolate_(json['message' + i], json['args' + i] || [], - json['lastDummyAlign' + i], warningPrefix); + this.interpolate_( + json['message' + i], json['args' + i] || [], json['lastDummyAlign' + i], + warningPrefix); i++; } @@ -1551,17 +1561,17 @@ Blockly.Block.prototype.jsonInit = function(json) { this.setNextStatement(true, json['nextStatement']); } if (json['tooltip'] !== undefined) { - var rawValue = json['tooltip']; - var localizedText = Blockly.utils.replaceMessageReferences(rawValue); + const rawValue = json['tooltip']; + const localizedText = utils.replaceMessageReferences(rawValue); this.setTooltip(localizedText); } if (json['enableContextMenu'] !== undefined) { - var rawValue = json['enableContextMenu']; + const rawValue = json['enableContextMenu']; this.contextMenu = !!rawValue; } if (json['helpUrl'] !== undefined) { - var rawValue = json['helpUrl']; - var localizedValue = Blockly.utils.replaceMessageReferences(rawValue); + const rawValue = json['helpUrl']; + const localizedValue = utils.replaceMessageReferences(rawValue); this.setHelpUrl(localizedValue); } if (typeof json['extensions'] == 'string') { @@ -1574,13 +1584,13 @@ Blockly.Block.prototype.jsonInit = function(json) { // Add the mutator to the block. if (json['mutator'] !== undefined) { - Blockly.Extensions.apply(json['mutator'], this, true); + Extensions.apply(json['mutator'], this, true); } - var extensionNames = json['extensions']; + const extensionNames = json['extensions']; if (Array.isArray(extensionNames)) { - for (var j = 0; j < extensionNames.length; ++j) { - Blockly.Extensions.apply(extensionNames[j], this, false); + for (let j = 0; j < extensionNames.length; ++j) { + Extensions.apply(extensionNames[j], this, false); } } }; @@ -1591,12 +1601,12 @@ Blockly.Block.prototype.jsonInit = function(json) { * @param {string} warningPrefix Warning prefix string identifying block. * @private */ -Blockly.Block.prototype.jsonInitColour_ = function(json, warningPrefix) { +Block.prototype.jsonInitColour_ = function(json, warningPrefix) { if ('colour' in json) { if (json['colour'] === undefined) { console.warn(warningPrefix + 'Undefined colour value.'); } else { - var rawValue = json['colour']; + const rawValue = json['colour']; try { this.setColour(rawValue); } catch (e) { @@ -1612,8 +1622,8 @@ Blockly.Block.prototype.jsonInitColour_ = function(json, warningPrefix) { * @param {string} warningPrefix Warning prefix string identifying block. * @private */ -Blockly.Block.prototype.jsonInitStyle_ = function(json, warningPrefix) { - var blockStyleName = json['style']; +Block.prototype.jsonInitStyle_ = function(json, warningPrefix) { + const blockStyleName = json['style']; try { this.setStyle(blockStyleName); } catch (styleError) { @@ -1630,23 +1640,23 @@ Blockly.Block.prototype.jsonInitStyle_ = function(json, warningPrefix) { * @param {!Object} mixinObj The key/values pairs to add to this block object. * @param {boolean=} opt_disableCheck Option flag to disable overwrite checks. */ -Blockly.Block.prototype.mixin = function(mixinObj, opt_disableCheck) { +Block.prototype.mixin = function(mixinObj, opt_disableCheck) { if (opt_disableCheck !== undefined && typeof opt_disableCheck != 'boolean') { throw Error('opt_disableCheck must be a boolean if provided'); } if (!opt_disableCheck) { - var overwrites = []; - for (var key in mixinObj) { + const overwrites = []; + for (let key in mixinObj) { if (this[key] !== undefined) { overwrites.push(key); } } if (overwrites.length) { - throw Error('Mixin will overwrite block members: ' + - JSON.stringify(overwrites)); + throw Error( + 'Mixin will overwrite block members: ' + JSON.stringify(overwrites)); } } - Blockly.utils.object.mixin(this, mixinObj); + object.mixin(this, mixinObj); }; /** @@ -1659,27 +1669,27 @@ Blockly.Block.prototype.mixin = function(mixinObj, opt_disableCheck) { * @param {string} warningPrefix Warning prefix string identifying block. * @private */ -Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign, - warningPrefix) { - var tokens = Blockly.utils.tokenizeInterpolation(message); +Block.prototype.interpolate_ = function( + message, args, lastDummyAlign, warningPrefix) { + const tokens = utils.tokenizeInterpolation(message); this.validateTokens_(tokens, args.length); - var elements = this.interpolateArguments_(tokens, args, lastDummyAlign); + const elements = this.interpolateArguments_(tokens, args, lastDummyAlign); // An array of [field, fieldName] tuples. - var fieldStack = []; - for (var i = 0, element; (element = elements[i]); i++) { + const fieldStack = []; + for (let i = 0, element; (element = elements[i]); i++) { if (this.isInputKeyword_(element['type'])) { - var input = this.inputFromJson_(element, warningPrefix); + const input = this.inputFromJson_(element, warningPrefix); // Should never be null, but just in case. if (input) { - for (var j = 0, tuple; (tuple = fieldStack[j]); j++) { + for (let j = 0, tuple; (tuple = fieldStack[j]); j++) { input.appendField(tuple[0], tuple[1]); } fieldStack.length = 0; } } else { // All other types, including ones starting with 'input_' get routed here. - var field = this.fieldFromJson_(element); + const field = this.fieldFromJson_(element); if (field) { fieldStack.push([field, element['name']]); } @@ -1695,27 +1705,30 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign, * @param {number} argsCount The number of args that need to be referred to. * @private */ -Blockly.Block.prototype.validateTokens_ = function(tokens, argsCount) { - var visitedArgsHash = []; - var visitedArgsCount = 0; - for (var i = 0; i < tokens.length; i++) { - var token = tokens[i]; +Block.prototype.validateTokens_ = function(tokens, argsCount) { + const visitedArgsHash = []; + let visitedArgsCount = 0; + for (let i = 0; i < tokens.length; i++) { + const token = tokens[i]; if (typeof token != 'number') { continue; } if (token < 1 || token > argsCount) { - throw Error('Block "' + this.type + '": ' + + throw Error( + 'Block "' + this.type + '": ' + 'Message index %' + token + ' out of range.'); } if (visitedArgsHash[token]) { - throw Error('Block "' + this.type + '": ' + + throw Error( + 'Block "' + this.type + '": ' + 'Message index %' + token + ' duplicated.'); } visitedArgsHash[token] = true; visitedArgsCount++; } if (visitedArgsCount != argsCount) { - throw Error('Block "' + this.type + '": ' + + throw Error( + 'Block "' + this.type + '": ' + 'Message does not reference all ' + argsCount + ' arg(s).'); } }; @@ -1732,35 +1745,34 @@ Blockly.Block.prototype.validateTokens_ = function(tokens, argsCount) { * to the block. * @private */ -Blockly.Block.prototype.interpolateArguments_ = - function(tokens, args, lastDummyAlign) { - var elements = []; - for (var i = 0; i < tokens.length; i++) { - var element = tokens[i]; - if (typeof element == 'number') { - element = args[element - 1]; - } - // Args can be strings, which is why this isn't elseif. - if (typeof element == 'string') { - element = this.stringToFieldJson_(element); - if (!element) { - continue; - } - } - elements.push(element); +Block.prototype.interpolateArguments_ = function(tokens, args, lastDummyAlign) { + const elements = []; + for (let i = 0; i < tokens.length; i++) { + let element = tokens[i]; + if (typeof element == 'number') { + element = args[element - 1]; + } + // Args can be strings, which is why this isn't elseif. + if (typeof element == 'string') { + element = this.stringToFieldJson_(element); + if (!element) { + continue; } + } + elements.push(element); + } - var length = elements.length; - if (length && !this.isInputKeyword_(elements[length - 1]['type'])) { - var dummyInput = {'type': 'input_dummy'}; - if (lastDummyAlign) { - dummyInput['align'] = lastDummyAlign; - } - elements.push(dummyInput); - } + const length = elements.length; + if (length && !this.isInputKeyword_(elements[length - 1]['type'])) { + const dummyInput = {'type': 'input_dummy'}; + if (lastDummyAlign) { + dummyInput['align'] = lastDummyAlign; + } + elements.push(dummyInput); + } - return elements; - }; + return elements; +}; /** * Creates a field from the JSON definition of a field. If a field with the @@ -1768,15 +1780,15 @@ Blockly.Block.prototype.interpolateArguments_ = * the 'alt' property of the JSON definition (if it exists). * @param {{alt:(string|undefined)}} element The element to try to turn into a * field. - * @return {?Blockly.Field} The field defined by the JSON, or null if one + * @return {?Field} The field defined by the JSON, or null if one * couldn't be created. * @private */ -Blockly.Block.prototype.fieldFromJson_ = function(element) { - var field = Blockly.fieldRegistry.fromJson(element); +Block.prototype.fieldFromJson_ = function(element) { + const field = fieldRegistry.fromJson(element); if (!field && element['alt']) { if (typeof element['alt'] == 'string') { - var json = this.stringToFieldJson_(element['alt']); + const json = this.stringToFieldJson_(element['alt']); return json ? this.fieldFromJson_(json) : null; } return this.fieldFromJson_(element['alt']); @@ -1790,19 +1802,19 @@ Blockly.Block.prototype.fieldFromJson_ = function(element) { * @param {!Object} element The JSON to turn into an input. * @param {string} warningPrefix The prefix to add to warnings to help the * developer debug. - * @return {?Blockly.Input} The input that has been created, or null if one + * @return {?Input} The input that has been created, or null if one * could not be created for some reason (should never happen). * @private */ -Blockly.Block.prototype.inputFromJson_ = function(element, warningPrefix) { - var alignmentLookup = { - 'LEFT': Blockly.constants.ALIGN.LEFT, - 'RIGHT': Blockly.constants.ALIGN.RIGHT, - 'CENTRE': Blockly.constants.ALIGN.CENTRE, - 'CENTER': Blockly.constants.ALIGN.CENTRE +Block.prototype.inputFromJson_ = function(element, warningPrefix) { + const alignmentLookup = { + 'LEFT': constants.ALIGN.LEFT, + 'RIGHT': constants.ALIGN.RIGHT, + 'CENTRE': constants.ALIGN.CENTRE, + 'CENTER': constants.ALIGN.CENTRE }; - var input = null; + let input = null; switch (element['type']) { case 'input_value': input = this.appendValueInput(element['name']); @@ -1823,10 +1835,9 @@ Blockly.Block.prototype.inputFromJson_ = function(element, warningPrefix) { input.setCheck(element['check']); } if (element['align']) { - var alignment = alignmentLookup[element['align'].toUpperCase()]; + const alignment = alignmentLookup[element['align'].toUpperCase()]; if (alignment === undefined) { - console.warn(warningPrefix + 'Illegal align value: ', - element['align']); + console.warn(warningPrefix + 'Illegal align value: ', element['align']); } else { input.setAlign(alignment); } @@ -1841,9 +1852,8 @@ Blockly.Block.prototype.inputFromJson_ = function(element, warningPrefix) { * false otherwise. * @private */ -Blockly.Block.prototype.isInputKeyword_ = function(str) { - return str == 'input_value' || - str == 'input_statement' || +Block.prototype.isInputKeyword_ = function(str) { + return str == 'input_value' || str == 'input_statement' || str == 'input_dummy'; }; @@ -1854,7 +1864,7 @@ Blockly.Block.prototype.isInputKeyword_ = function(str) { * @return {?{text: string, type: string}} The JSON definition or null. * @private */ -Blockly.Block.prototype.stringToFieldJson_ = function(str) { +Block.prototype.stringToFieldJson_ = function(str) { str = str.trim(); if (str) { return { @@ -1870,19 +1880,18 @@ Blockly.Block.prototype.stringToFieldJson_ = function(str) { * @param {number} type One of Blockly.inputTypes. * @param {string} name Language-neutral identifier which may used to find this * input again. Should be unique to this block. - * @return {!Blockly.Input} The input object created. + * @return {!Input} The input object created. * @protected */ -Blockly.Block.prototype.appendInput_ = function(type, name) { - var connection = null; - if (type == Blockly.inputTypes.VALUE || - type == Blockly.inputTypes.STATEMENT) { +Block.prototype.appendInput_ = function(type, name) { + let connection = null; + if (type == inputTypes.VALUE || type == inputTypes.STATEMENT) { connection = this.makeConnection_(type); } - if (type == Blockly.inputTypes.STATEMENT) { + if (type == inputTypes.STATEMENT) { this.statementInputCount++; } - var input = new Blockly.Input(type, name, this, connection); + const input = new Input(type, name, this, connection); // Append input to list. this.inputList.push(input); return input; @@ -1894,14 +1903,14 @@ Blockly.Block.prototype.appendInput_ = function(type, name) { * @param {?string} refName Name of input that should be after the moved input, * or null to be the input at the end. */ -Blockly.Block.prototype.moveInputBefore = function(name, refName) { +Block.prototype.moveInputBefore = function(name, refName) { if (name == refName) { return; } // Find both inputs. - var inputIndex = -1; - var refIndex = refName ? -1 : this.inputList.length; - for (var i = 0, input; (input = this.inputList[i]); i++) { + let inputIndex = -1; + let refIndex = refName ? -1 : this.inputList.length; + for (let i = 0, input; (input = this.inputList[i]); i++) { if (input.name == name) { inputIndex = i; if (refIndex != -1) { @@ -1928,8 +1937,7 @@ Blockly.Block.prototype.moveInputBefore = function(name, refName) { * @param {number} inputIndex Index of the input to move. * @param {number} refIndex Index of input that should be after the moved input. */ -Blockly.Block.prototype.moveNumberedInputBefore = function( - inputIndex, refIndex) { +Block.prototype.moveNumberedInputBefore = function(inputIndex, refIndex) { // Validate arguments. if (inputIndex == refIndex) { throw Error('Can\'t move input to itself.'); @@ -1941,7 +1949,7 @@ Blockly.Block.prototype.moveNumberedInputBefore = function( throw RangeError('Reference input ' + refIndex + ' out of bounds.'); } // Remove input. - var input = this.inputList[inputIndex]; + const input = this.inputList[inputIndex]; this.inputList.splice(inputIndex, 1); if (inputIndex < refIndex) { refIndex--; @@ -1954,13 +1962,14 @@ Blockly.Block.prototype.moveNumberedInputBefore = function( * Remove an input from this block. * @param {string} name The name of the input. * @param {boolean=} opt_quiet True to prevent an error if input is not present. - * @return {boolean} True if operation succeeds, false if input is not present and opt_quiet is true + * @return {boolean} True if operation succeeds, false if input is not present + * and opt_quiet is true. * @throws {Error} if the input is not present and opt_quiet is not true. */ -Blockly.Block.prototype.removeInput = function(name, opt_quiet) { - for (var i = 0, input; (input = this.inputList[i]); i++) { +Block.prototype.removeInput = function(name, opt_quiet) { + for (let i = 0, input; (input = this.inputList[i]); i++) { if (input.name == name) { - if (input.type == Blockly.inputTypes.STATEMENT) { + if (input.type == inputTypes.STATEMENT) { this.statementInputCount--; } input.dispose(); @@ -1977,10 +1986,10 @@ Blockly.Block.prototype.removeInput = function(name, opt_quiet) { /** * Fetches the named input object. * @param {string} name The name of the input. - * @return {?Blockly.Input} The input object, or null if input does not exist. + * @return {?Input} The input object, or null if input does not exist. */ -Blockly.Block.prototype.getInput = function(name) { - for (var i = 0, input; (input = this.inputList[i]); i++) { +Block.prototype.getInput = function(name) { + for (let i = 0, input; (input = this.inputList[i]); i++) { if (input.name == name) { return input; } @@ -1992,11 +2001,11 @@ Blockly.Block.prototype.getInput = function(name) { /** * Fetches the block attached to the named input. * @param {string} name The name of the input. - * @return {?Blockly.Block} The attached value block, or null if the input is + * @return {?Block} The attached value block, or null if the input is * either disconnected or if the input does not exist. */ -Blockly.Block.prototype.getInputTargetBlock = function(name) { - var input = this.getInput(name); +Block.prototype.getInputTargetBlock = function(name) { + const input = this.getInput(name); return input && input.connection && input.connection.targetBlock(); }; @@ -2004,7 +2013,7 @@ Blockly.Block.prototype.getInputTargetBlock = function(name) { * Returns the comment on this block (or null if there is no comment). * @return {?string} Block's comment. */ -Blockly.Block.prototype.getCommentText = function() { +Block.prototype.getCommentText = function() { return this.commentModel.text; }; @@ -2012,11 +2021,11 @@ Blockly.Block.prototype.getCommentText = function() { * Set this block's comment text. * @param {?string} text The text, or null to delete. */ -Blockly.Block.prototype.setCommentText = function(text) { +Block.prototype.setCommentText = function(text) { if (this.commentModel.text == text) { return; } - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this, 'comment', null, this.commentModel.text, text)); this.commentModel.text = text; this.comment = text; // For backwards compatibility. @@ -2028,25 +2037,25 @@ Blockly.Block.prototype.setCommentText = function(text) { * @param {string=} _opt_id An optional ID for the warning text to be able to * maintain multiple warnings. */ -Blockly.Block.prototype.setWarningText = function(_text, _opt_id) { +Block.prototype.setWarningText = function(_text, _opt_id) { // NOP. }; /** * Give this block a mutator dialog. - * @param {Blockly.Mutator} _mutator A mutator dialog instance or null to + * @param {Mutator} _mutator A mutator dialog instance or null to * remove. */ -Blockly.Block.prototype.setMutator = function(_mutator) { +Block.prototype.setMutator = function(_mutator) { // NOP. }; /** * Return the coordinates of the top-left corner of this block relative to the * drawing surface's origin (0,0), in workspace units. - * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. + * @return {!Coordinate} Object with .x and .y properties. */ -Blockly.Block.prototype.getRelativeToSurfaceXY = function() { +Block.prototype.getRelativeToSurfaceXY = function() { return this.xy_; }; @@ -2055,24 +2064,24 @@ Blockly.Block.prototype.getRelativeToSurfaceXY = function() { * @param {number} dx Horizontal offset, in workspace units. * @param {number} dy Vertical offset, in workspace units. */ -Blockly.Block.prototype.moveBy = function(dx, dy) { +Block.prototype.moveBy = function(dx, dy) { if (this.parentBlock_) { throw Error('Block has parent.'); } - var event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this); + const event = new (Events.get(Events.BLOCK_MOVE))(this); this.xy_.translate(dx, dy); event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); }; /** * Create a connection of the specified type. * @param {number} type The type of the connection to create. - * @return {!Blockly.Connection} A new connection of the specified type. + * @return {!Connection} A new connection of the specified type. * @protected */ -Blockly.Block.prototype.makeConnection_ = function(type) { - return new Blockly.Connection(this, type); +Block.prototype.makeConnection_ = function(type) { + return new Connection(this, type); }; /** @@ -2082,7 +2091,7 @@ Blockly.Block.prototype.makeConnection_ = function(type) { * whether shadow blocks are counted as filled. Defaults to true. * @return {boolean} True if all inputs are filled, false otherwise. */ -Blockly.Block.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled) { +Block.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled) { // Account for the shadow block filledness toggle. if (opt_shadowBlocksAreFilled === undefined) { opt_shadowBlocksAreFilled = true; @@ -2092,18 +2101,18 @@ Blockly.Block.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled) { } // Recursively check each input block of the current block. - for (var i = 0, input; (input = this.inputList[i]); i++) { + for (let i = 0, input; (input = this.inputList[i]); i++) { if (!input.connection) { continue; } - var target = input.connection.targetBlock(); + const target = input.connection.targetBlock(); if (!target || !target.allInputsFilled(opt_shadowBlocksAreFilled)) { return false; } } // Recursively check the next block after the current block. - var next = this.getNextBlock(); + const next = this.getNextBlock(); if (next) { return next.allInputsFilled(opt_shadowBlocksAreFilled); } @@ -2117,13 +2126,15 @@ Blockly.Block.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled) { * * Intended to on be used in console logs and errors. If you need a string that * uses the user's native language (including block text, field values, and - * child blocks), use [toString()]{@link Blockly.Block#toString}. + * child blocks), use [toString()]{@link Block#toString}. * @return {string} The description. */ -Blockly.Block.prototype.toDevString = function() { - var msg = this.type ? '"' + this.type + '" block' : 'Block'; +Block.prototype.toDevString = function() { + let msg = this.type ? '"' + this.type + '" block' : 'Block'; if (this.id) { msg += ' (id="' + this.id + '")'; } return msg; }; + +exports = Block; diff --git a/tests/deps.js b/tests/deps.js index ff7e2926e..641b435a5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -7,7 +7,7 @@ goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); -goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); +goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.common', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'});