diff --git a/core/events/events_block_base.js b/core/events/events_block_base.js index c1c0ebb61..2ba798689 100644 --- a/core/events/events_block_base.js +++ b/core/events/events_block_base.js @@ -51,7 +51,7 @@ Blockly.utils.object.inherits(Blockly.Events.BlockBase, * @return {!Object} JSON representation. */ Blockly.Events.BlockBase.prototype.toJson = function() { - var json = Blockly.Events.BlockBase.superClass_.toJson.call(this); + const json = Blockly.Events.BlockBase.superClass_.toJson.call(this); json['blockId'] = this.blockId; return json; }; diff --git a/core/events/events_block_change.js b/core/events/events_block_change.js index 82868aac2..6938712b0 100644 --- a/core/events/events_block_change.js +++ b/core/events/events_block_change.js @@ -54,7 +54,7 @@ Blockly.Events.BlockChange.prototype.type = Blockly.Events.BLOCK_CHANGE; * @return {!Object} JSON representation. */ Blockly.Events.BlockChange.prototype.toJson = function() { - var json = Blockly.Events.BlockChange.superClass_.toJson.call(this); + const json = Blockly.Events.BlockChange.superClass_.toJson.call(this); json['element'] = this.element; if (this.name) { json['name'] = this.name; @@ -89,8 +89,8 @@ Blockly.Events.BlockChange.prototype.isNull = function() { * @param {boolean} forward True if run forward, false if run backward (undo). */ Blockly.Events.BlockChange.prototype.run = function(forward) { - var workspace = this.getEventWorkspace_(); - var block = workspace.getBlockById(this.blockId); + const workspace = this.getEventWorkspace_(); + const block = workspace.getBlockById(this.blockId); if (!block) { console.warn("Can't change non-existent block: " + this.blockId); return; @@ -99,16 +99,17 @@ Blockly.Events.BlockChange.prototype.run = function(forward) { // Close the mutator (if open) since we don't want to update it. block.mutator.setVisible(false); } - var value = forward ? this.newValue : this.oldValue; + const value = forward ? this.newValue : this.oldValue; switch (this.element) { - case 'field': - var field = block.getField(this.name); + case 'field': { + const field = block.getField(this.name); if (field) { field.setValue(value); } else { console.warn("Can't set non-existent field: " + this.name); } break; + } case 'comment': block.setCommentText(/** @type {string} */ (value) || null); break; @@ -121,19 +122,21 @@ Blockly.Events.BlockChange.prototype.run = function(forward) { case 'inline': block.setInputsInline(!!value); break; - case 'mutation': - var oldMutation = ''; + case 'mutation': { + let oldMutation = ''; if (block.mutationToDom) { - var oldMutationDom = block.mutationToDom(); + const oldMutationDom = block.mutationToDom(); oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom); } if (block.domToMutation) { - var dom = Blockly.Xml.textToDom(/** @type {string} */ (value) || ''); + const dom = Blockly.Xml.textToDom(/** @type {string} */ + (value) || ''); block.domToMutation(dom); } Blockly.Events.fire(new Blockly.Events.BlockChange( block, 'mutation', null, oldMutation, value)); break; + } default: console.warn('Unknown change type: ' + this.element); } diff --git a/core/events/events_block_create.js b/core/events/events_block_create.js index 301068afe..119f9c0a8 100644 --- a/core/events/events_block_create.js +++ b/core/events/events_block_create.js @@ -58,7 +58,7 @@ Blockly.Events.BlockCreate.prototype.type = Blockly.Events.BLOCK_CREATE; * @return {!Object} JSON representation. */ Blockly.Events.BlockCreate.prototype.toJson = function() { - var json = Blockly.Events.BlockCreate.superClass_.toJson.call(this); + const json = Blockly.Events.BlockCreate.superClass_.toJson.call(this); json['xml'] = Blockly.Xml.domToText(this.xml); json['ids'] = this.ids; if (!this.recordUndo) { @@ -85,14 +85,15 @@ Blockly.Events.BlockCreate.prototype.fromJson = function(json) { * @param {boolean} forward True if run forward, false if run backward (undo). */ Blockly.Events.BlockCreate.prototype.run = function(forward) { - var workspace = this.getEventWorkspace_(); + const workspace = this.getEventWorkspace_(); if (forward) { - var xml = Blockly.utils.xml.createElement('xml'); + const xml = Blockly.utils.xml.createElement('xml'); xml.appendChild(this.xml); Blockly.Xml.domToWorkspace(xml, workspace); } else { - for (var i = 0, id; (id = this.ids[i]); i++) { - var block = workspace.getBlockById(id); + for (let i = 0; i < this.ids.length; i++) { + const id = this.ids[i]; + const block = workspace.getBlockById(id); if (block) { block.dispose(false); } else if (id == this.blockId) { diff --git a/core/events/events_block_delete.js b/core/events/events_block_delete.js index 38d1d6345..120ac7ddc 100644 --- a/core/events/events_block_delete.js +++ b/core/events/events_block_delete.js @@ -62,7 +62,7 @@ Blockly.Events.BlockDelete.prototype.type = Blockly.Events.BLOCK_DELETE; * @return {!Object} JSON representation. */ Blockly.Events.BlockDelete.prototype.toJson = function() { - var json = Blockly.Events.BlockDelete.superClass_.toJson.call(this); + const json = Blockly.Events.BlockDelete.superClass_.toJson.call(this); json['oldXml'] = Blockly.Xml.domToText(this.oldXml); json['ids'] = this.ids; if (!this.recordUndo) { @@ -89,10 +89,11 @@ Blockly.Events.BlockDelete.prototype.fromJson = function(json) { * @param {boolean} forward True if run forward, false if run backward (undo). */ Blockly.Events.BlockDelete.prototype.run = function(forward) { - var workspace = this.getEventWorkspace_(); + const workspace = this.getEventWorkspace_(); if (forward) { - for (var i = 0, id; (id = this.ids[i]); i++) { - var block = workspace.getBlockById(id); + for (let i = 0; i < this.ids.length; i++) { + const id = this.ids[i]; + const block = workspace.getBlockById(id); if (block) { block.dispose(false); } else if (id == this.blockId) { @@ -101,7 +102,7 @@ Blockly.Events.BlockDelete.prototype.run = function(forward) { } } } else { - var xml = Blockly.utils.xml.createElement('xml'); + const xml = Blockly.utils.xml.createElement('xml'); xml.appendChild(this.oldXml); Blockly.Xml.domToWorkspace(xml, workspace); } diff --git a/core/events/events_block_move.js b/core/events/events_block_move.js index d3121e115..4318e443e 100644 --- a/core/events/events_block_move.js +++ b/core/events/events_block_move.js @@ -39,7 +39,7 @@ Blockly.Events.BlockMove = function(opt_block) { this.recordUndo = false; } - var location = this.currentLocation_(); + const location = this.currentLocation_(); this.oldParentId = location.parentId; this.oldInputName = location.inputName; this.oldCoordinate = location.coordinate; @@ -57,7 +57,7 @@ Blockly.Events.BlockMove.prototype.type = Blockly.Events.BLOCK_MOVE; * @return {!Object} JSON representation. */ Blockly.Events.BlockMove.prototype.toJson = function() { - var json = Blockly.Events.BlockMove.superClass_.toJson.call(this); + const json = Blockly.Events.BlockMove.superClass_.toJson.call(this); if (this.newParentId) { json['newParentId'] = this.newParentId; } @@ -83,7 +83,7 @@ Blockly.Events.BlockMove.prototype.fromJson = function(json) { this.newParentId = json['newParentId']; this.newInputName = json['newInputName']; if (json['newCoordinate']) { - var xy = json['newCoordinate'].split(','); + const xy = json['newCoordinate'].split(','); this.newCoordinate = new Blockly.utils.Coordinate(Number(xy[0]), Number(xy[1])); } @@ -96,7 +96,7 @@ Blockly.Events.BlockMove.prototype.fromJson = function(json) { * Record the block's new location. Called after the move. */ Blockly.Events.BlockMove.prototype.recordNew = function() { - var location = this.currentLocation_(); + const location = this.currentLocation_(); this.newParentId = location.parentId; this.newInputName = location.inputName; this.newCoordinate = location.coordinate; @@ -109,13 +109,13 @@ Blockly.Events.BlockMove.prototype.recordNew = function() { * @private */ Blockly.Events.BlockMove.prototype.currentLocation_ = function() { - var workspace = this.getEventWorkspace_(); - var block = workspace.getBlockById(this.blockId); - var location = {}; - var parent = block.getParent(); + const workspace = this.getEventWorkspace_(); + const block = workspace.getBlockById(this.blockId); + const location = {}; + const parent = block.getParent(); if (parent) { location.parentId = parent.id; - var input = parent.getInputWithBlock(block); + const input = parent.getInputWithBlock(block); if (input) { location.inputName = input.name; } @@ -140,16 +140,16 @@ Blockly.Events.BlockMove.prototype.isNull = function() { * @param {boolean} forward True if run forward, false if run backward (undo). */ Blockly.Events.BlockMove.prototype.run = function(forward) { - var workspace = this.getEventWorkspace_(); - var block = workspace.getBlockById(this.blockId); + const workspace = this.getEventWorkspace_(); + const block = workspace.getBlockById(this.blockId); if (!block) { console.warn("Can't move non-existent block: " + this.blockId); return; } - var parentId = forward ? this.newParentId : this.oldParentId; - var inputName = forward ? this.newInputName : this.oldInputName; - var coordinate = forward ? this.newCoordinate : this.oldCoordinate; - var parentBlock = null; + const parentId = forward ? this.newParentId : this.oldParentId; + const inputName = forward ? this.newInputName : this.oldInputName; + const coordinate = forward ? this.newCoordinate : this.oldCoordinate; + let parentBlock; if (parentId) { parentBlock = workspace.getBlockById(parentId); if (!parentBlock) { @@ -161,14 +161,14 @@ Blockly.Events.BlockMove.prototype.run = function(forward) { block.unplug(); } if (coordinate) { - var xy = block.getRelativeToSurfaceXY(); + const xy = block.getRelativeToSurfaceXY(); block.moveBy(coordinate.x - xy.x, coordinate.y - xy.y); } else { - var blockConnection = block.outputConnection || block.previousConnection; - var parentConnection; - var connectionType = blockConnection.type; + const blockConnection = block.outputConnection || block.previousConnection; + let parentConnection; + const connectionType = blockConnection.type; if (inputName) { - var input = parentBlock.getInput(inputName); + const input = parentBlock.getInput(inputName); if (input) { parentConnection = input.connection; }