chore: replace var with const and let in blocks directory (#5626)

* chore: use const and let in blocks/lists.js

* chore: use const and let in blocks/logic.js

* chore: use const and let in blocks/loops.js

* chore: use const and let in blocks/math.js

* chore: use const and let in blocks/procedures.js

* chore: use const and let in blocks/text.js

* chore: use const and let in blocks/variables_dynamic.js

* chore: use const and let in blocks/variables.js

* fix: updateShape_ variable scoping

* fix: declarations in switch clauses

* other: change while loops to for loops

* fix: fix violation of no-cond-assign
This commit is contained in:
Rachel Fenichel
2021-10-21 14:25:37 -07:00
committed by GitHub
parent e8d6f7f408
commit 6dc0f90959
8 changed files with 329 additions and 331 deletions

View File

@@ -134,7 +134,7 @@ Blockly.Blocks['lists_create_with'] = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('items', this.itemCount_);
return container;
},
@@ -172,11 +172,11 @@ Blockly.Blocks['lists_create_with'] = {
* @this {Blockly.Block}
*/
decompose: function(workspace) {
var containerBlock = workspace.newBlock('lists_create_with_container');
const containerBlock = workspace.newBlock('lists_create_with_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('lists_create_with_item');
let connection = containerBlock.getInput('STACK').connection;
for (let i = 0; i < this.itemCount_; i++) {
const itemBlock = workspace.newBlock('lists_create_with_item');
itemBlock.initSvg();
connection.connect(itemBlock.previousConnection);
connection = itemBlock.nextConnection;
@@ -189,17 +189,17 @@ Blockly.Blocks['lists_create_with'] = {
* @this {Blockly.Block}
*/
compose: function(containerBlock) {
var itemBlock = containerBlock.getInputTargetBlock('STACK');
let itemBlock = containerBlock.getInputTargetBlock('STACK');
// Count number of inputs.
var connections = [];
const connections = [];
while (itemBlock && !itemBlock.isInsertionMarker()) {
connections.push(itemBlock.valueConnection_);
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
}
// Disconnect any children that don't belong.
for (var i = 0; i < this.itemCount_; i++) {
var connection = this.getInput('ADD' + i).connection.targetConnection;
for (let i = 0; i < this.itemCount_; i++) {
const connection = this.getInput('ADD' + i).connection.targetConnection;
if (connection && connections.indexOf(connection) === -1) {
connection.disconnect();
}
@@ -207,7 +207,7 @@ Blockly.Blocks['lists_create_with'] = {
this.itemCount_ = connections.length;
this.updateShape_();
// Reconnect any child blocks.
for (var i = 0; i < this.itemCount_; i++) {
for (let i = 0; i < this.itemCount_; i++) {
Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
}
},
@@ -217,14 +217,14 @@ Blockly.Blocks['lists_create_with'] = {
* @this {Blockly.Block}
*/
saveConnections: function(containerBlock) {
var itemBlock = containerBlock.getInputTargetBlock('STACK');
var i = 0;
let itemBlock = containerBlock.getInputTargetBlock('STACK');
let i = 0;
while (itemBlock) {
var input = this.getInput('ADD' + i);
const input = this.getInput('ADD' + i);
itemBlock.valueConnection_ = input && input.connection.targetConnection;
itemBlock =
itemBlock.nextConnection && itemBlock.nextConnection.targetBlock();
i++;
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
}
},
/**
@@ -240,9 +240,9 @@ Blockly.Blocks['lists_create_with'] = {
.appendField(Blockly.Msg['LISTS_CREATE_EMPTY_TITLE']);
}
// Add new inputs.
for (var i = 0; i < this.itemCount_; i++) {
for (let i = 0; i < this.itemCount_; i++) {
if (!this.getInput('ADD' + i)) {
var input = this.appendValueInput('ADD' + i)
const input = this.appendValueInput('ADD' + i)
.setAlign(Blockly.ALIGN_RIGHT);
if (i === 0) {
input.appendField(Blockly.Msg['LISTS_CREATE_WITH_INPUT_WITH']);
@@ -250,9 +250,8 @@ Blockly.Blocks['lists_create_with'] = {
}
}
// Remove deleted inputs.
while (this.getInput('ADD' + i)) {
for (let i = this.itemCount_; this.getInput('ADD' + i); i++) {
this.removeInput('ADD' + i);
i++;
}
},
};
@@ -294,7 +293,7 @@ Blockly.Blocks['lists_indexOf'] = {
* @this {Blockly.Block}
*/
init: function() {
var OPERATORS =
const OPERATORS =
[
[Blockly.Msg['LISTS_INDEX_OF_FIRST'], 'FIRST'],
[Blockly.Msg['LISTS_INDEX_OF_LAST'], 'LAST'],
@@ -309,7 +308,7 @@ Blockly.Blocks['lists_indexOf'] = {
.appendField(new Blockly.FieldDropdown(OPERATORS), 'END');
this.setInputsInline(true);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
const thisBlock = this;
this.setTooltip(function() {
return Blockly.Msg['LISTS_INDEX_OF_TOOLTIP'].replace('%1',
thisBlock.workspace.options.oneBasedIndex ? '0' : '-1');
@@ -323,7 +322,7 @@ Blockly.Blocks['lists_getIndex'] = {
* @this {Blockly.Block}
*/
init: function() {
var MODE =
const MODE =
[
[Blockly.Msg['LISTS_GET_INDEX_GET'], 'GET'],
[Blockly.Msg['LISTS_GET_INDEX_GET_REMOVE'], 'GET_REMOVE'],
@@ -339,8 +338,8 @@ Blockly.Blocks['lists_getIndex'] = {
];
this.setHelpUrl(Blockly.Msg['LISTS_GET_INDEX_HELPURL']);
this.setStyle('list_blocks');
var modeMenu = new Blockly.FieldDropdown(MODE, function(value) {
var isStatement = (value === 'REMOVE');
const modeMenu = new Blockly.FieldDropdown(MODE, function(value) {
const isStatement = (value === 'REMOVE');
this.getSourceBlock().updateStatement_(isStatement);
});
this.appendValueInput('VALUE')
@@ -358,11 +357,11 @@ Blockly.Blocks['lists_getIndex'] = {
this.setOutput(true);
this.updateAt_(true);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
const thisBlock = this;
this.setTooltip(function() {
var mode = thisBlock.getFieldValue('MODE');
var where = thisBlock.getFieldValue('WHERE');
var tooltip = '';
const mode = thisBlock.getFieldValue('MODE');
const where = thisBlock.getFieldValue('WHERE');
let tooltip = '';
switch (mode + ' ' + where) {
case 'GET FROM_START':
case 'GET FROM_END':
@@ -405,7 +404,7 @@ Blockly.Blocks['lists_getIndex'] = {
break;
}
if (where === 'FROM_START' || where === 'FROM_END') {
var msg = (where === 'FROM_START') ?
const msg = (where === 'FROM_START') ?
Blockly.Msg['LISTS_INDEX_FROM_START_TOOLTIP'] :
Blockly.Msg['LISTS_INDEX_FROM_END_TOOLTIP'];
tooltip += ' ' + msg.replace('%1',
@@ -421,10 +420,10 @@ Blockly.Blocks['lists_getIndex'] = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
var isStatement = !this.outputConnection;
const container = Blockly.utils.xml.createElement('mutation');
const isStatement = !this.outputConnection;
container.setAttribute('statement', isStatement);
var isAt = this.getInput('AT').type === Blockly.INPUT_VALUE;
const isAt = this.getInput('AT').type === Blockly.INPUT_VALUE;
container.setAttribute('at', isAt);
return container;
},
@@ -436,12 +435,12 @@ Blockly.Blocks['lists_getIndex'] = {
domToMutation: function(xmlElement) {
// Note: Until January 2013 this block did not have mutations,
// so 'statement' defaults to false and 'at' defaults to true.
var isStatement = (xmlElement.getAttribute('statement') === 'true');
const isStatement = (xmlElement.getAttribute('statement') === 'true');
this.updateStatement_(isStatement);
var isAt = (xmlElement.getAttribute('at') !== 'false');
const isAt = (xmlElement.getAttribute('at') !== 'false');
this.updateAt_(isAt);
},
// This block does not need JSO serialization hooks (saveExtraState and
// loadExtraState) because the state of this object is already encoded in the
// dropdown values.
@@ -455,7 +454,7 @@ Blockly.Blocks['lists_getIndex'] = {
* @this {Blockly.Block}
*/
updateStatement_: function(newStatement) {
var oldStatement = !this.outputConnection;
const oldStatement = !this.outputConnection;
if (newStatement !== oldStatement) {
this.unplug(true, true);
if (newStatement) {
@@ -489,11 +488,11 @@ Blockly.Blocks['lists_getIndex'] = {
} else {
this.appendDummyInput('AT');
}
var menu = new Blockly.FieldDropdown(this.WHERE_OPTIONS, function(value) {
var newAt = (value === 'FROM_START') || (value === 'FROM_END');
const menu = new Blockly.FieldDropdown(this.WHERE_OPTIONS, function(value) {
const newAt = (value === 'FROM_START') || (value === 'FROM_END');
// The 'isAt' variable is available due to this function being a closure.
if (newAt !== isAt) {
var block = this.getSourceBlock();
const block = this.getSourceBlock();
block.updateAt_(newAt);
// This menu has been destroyed and replaced. Update the replacement.
block.setFieldValue(value, 'WHERE');
@@ -514,7 +513,7 @@ Blockly.Blocks['lists_setIndex'] = {
* @this {Blockly.Block}
*/
init: function() {
var MODE =
const MODE =
[
[Blockly.Msg['LISTS_SET_INDEX_SET'], 'SET'],
[Blockly.Msg['LISTS_SET_INDEX_INSERT'], 'INSERT'],
@@ -544,11 +543,11 @@ Blockly.Blocks['lists_setIndex'] = {
this.setTooltip(Blockly.Msg['LISTS_SET_INDEX_TOOLTIP']);
this.updateAt_(true);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
const thisBlock = this;
this.setTooltip(function() {
var mode = thisBlock.getFieldValue('MODE');
var where = thisBlock.getFieldValue('WHERE');
var tooltip = '';
const mode = thisBlock.getFieldValue('MODE');
const where = thisBlock.getFieldValue('WHERE');
let tooltip = '';
switch (mode + ' ' + where) {
case 'SET FROM_START':
case 'SET FROM_END':
@@ -591,8 +590,8 @@ Blockly.Blocks['lists_setIndex'] = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
var isAt = this.getInput('AT').type === Blockly.INPUT_VALUE;
const container = Blockly.utils.xml.createElement('mutation');
const isAt = this.getInput('AT').type === Blockly.INPUT_VALUE;
container.setAttribute('at', isAt);
return container;
},
@@ -604,10 +603,10 @@ Blockly.Blocks['lists_setIndex'] = {
domToMutation: function(xmlElement) {
// Note: Until January 2013 this block did not have mutations,
// so 'at' defaults to true.
var isAt = (xmlElement.getAttribute('at') !== 'false');
const isAt = (xmlElement.getAttribute('at') !== 'false');
this.updateAt_(isAt);
},
// This block does not need JSO serialization hooks (saveExtraState and
// loadExtraState) because the state of this object is already encoded in the
// dropdown values.
@@ -633,11 +632,11 @@ Blockly.Blocks['lists_setIndex'] = {
} else {
this.appendDummyInput('AT');
}
var menu = new Blockly.FieldDropdown(this.WHERE_OPTIONS, function(value) {
var newAt = (value === 'FROM_START') || (value === 'FROM_END');
const menu = new Blockly.FieldDropdown(this.WHERE_OPTIONS, function(value) {
const newAt = (value === 'FROM_START') || (value === 'FROM_END');
// The 'isAt' variable is available due to this function being a closure.
if (newAt !== isAt) {
var block = this.getSourceBlock();
const block = this.getSourceBlock();
block.updateAt_(newAt);
// This menu has been destroyed and replaced. Update the replacement.
block.setFieldValue(value, 'WHERE');
@@ -695,10 +694,10 @@ Blockly.Blocks['lists_getSublist'] = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
var isAt1 = this.getInput('AT1').type === Blockly.INPUT_VALUE;
const container = Blockly.utils.xml.createElement('mutation');
const isAt1 = this.getInput('AT1').type === Blockly.INPUT_VALUE;
container.setAttribute('at1', isAt1);
var isAt2 = this.getInput('AT2').type === Blockly.INPUT_VALUE;
const isAt2 = this.getInput('AT2').type === Blockly.INPUT_VALUE;
container.setAttribute('at2', isAt2);
return container;
},
@@ -708,12 +707,12 @@ Blockly.Blocks['lists_getSublist'] = {
* @this {Blockly.Block}
*/
domToMutation: function(xmlElement) {
var isAt1 = (xmlElement.getAttribute('at1') === 'true');
var isAt2 = (xmlElement.getAttribute('at2') === 'true');
const isAt1 = (xmlElement.getAttribute('at1') === 'true');
const isAt2 = (xmlElement.getAttribute('at2') === 'true');
this.updateAt_(1, isAt1);
this.updateAt_(2, isAt2);
},
// This block does not need JSO serialization hooks (saveExtraState and
// loadExtraState) because the state of this object is already encoded in the
// dropdown values.
@@ -742,13 +741,13 @@ Blockly.Blocks['lists_getSublist'] = {
} else {
this.appendDummyInput('AT' + n);
}
var menu = new Blockly.FieldDropdown(this['WHERE_OPTIONS_' + n],
const menu = new Blockly.FieldDropdown(this['WHERE_OPTIONS_' + n],
function(value) {
var newAt = (value === 'FROM_START') || (value === 'FROM_END');
const newAt = (value === 'FROM_START') || (value === 'FROM_END');
// The 'isAt' variable is available due to this function being a
// closure.
if (newAt !== isAt) {
var block = this.getSourceBlock();
const block = this.getSourceBlock();
block.updateAt_(n, newAt);
// This menu has been destroyed and replaced.
// Update the replacement.
@@ -817,8 +816,8 @@ Blockly.Blocks['lists_split'] = {
*/
init: function() {
// Assign 'this' to a variable for use in the closures below.
var thisBlock = this;
var dropdown = new Blockly.FieldDropdown(
const thisBlock = this;
const dropdown = new Blockly.FieldDropdown(
[
[Blockly.Msg['LISTS_SPLIT_LIST_FROM_TEXT'], 'SPLIT'],
[Blockly.Msg['LISTS_SPLIT_TEXT_FROM_LIST'], 'JOIN'],
@@ -837,7 +836,7 @@ Blockly.Blocks['lists_split'] = {
this.setInputsInline(true);
this.setOutput(true, 'Array');
this.setTooltip(function() {
var mode = thisBlock.getFieldValue('MODE');
const mode = thisBlock.getFieldValue('MODE');
if (mode === 'SPLIT') {
return Blockly.Msg['LISTS_SPLIT_TOOLTIP_SPLIT'];
} else if (mode === 'JOIN') {
@@ -853,11 +852,11 @@ Blockly.Blocks['lists_split'] = {
* @this {Blockly.Block}
*/
updateType_: function(newMode) {
var mode = this.getFieldValue('MODE');
const mode = this.getFieldValue('MODE');
if (mode !== newMode) {
var inputConnection = this.getInput('INPUT').connection;
const inputConnection = this.getInput('INPUT').connection;
inputConnection.setShadowDom(null);
var inputBlock = inputConnection.targetBlock();
const inputBlock = inputConnection.targetBlock();
if (inputBlock) {
inputConnection.disconnect();
if (inputBlock.isShadow()) {
@@ -881,7 +880,7 @@ Blockly.Blocks['lists_split'] = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('mode', this.getFieldValue('MODE'));
return container;
},
@@ -893,7 +892,7 @@ Blockly.Blocks['lists_split'] = {
domToMutation: function(xmlElement) {
this.updateType_(xmlElement.getAttribute('mode'));
},
// This block does not need JSO serialization hooks (saveExtraState and
// loadExtraState) because the state of this object is already encoded in the
// dropdown values.

View File

@@ -305,7 +305,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
if (!this.elseifCount_ && !this.elseCount_) {
return null;
}
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
if (this.elseifCount_) {
container.setAttribute('elseif', this.elseifCount_);
}
@@ -334,7 +334,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
if (!this.elseifCount_ && !this.elseCount_) {
return null;
}
var state = Object.create(null);
const state = Object.create(null);
if (this.elseifCount_) {
state['elseIfCount'] = this.elseifCount_;
}
@@ -360,17 +360,17 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
decompose: function(workspace) {
var containerBlock = workspace.newBlock('controls_if_if');
const containerBlock = workspace.newBlock('controls_if_if');
containerBlock.initSvg();
var connection = containerBlock.nextConnection;
for (var i = 1; i <= this.elseifCount_; i++) {
var elseifBlock = workspace.newBlock('controls_if_elseif');
let connection = containerBlock.nextConnection;
for (let i = 1; i <= this.elseifCount_; i++) {
const elseifBlock = workspace.newBlock('controls_if_elseif');
elseifBlock.initSvg();
connection.connect(elseifBlock.previousConnection);
connection = elseifBlock.nextConnection;
}
if (this.elseCount_) {
var elseBlock = workspace.newBlock('controls_if_else');
const elseBlock = workspace.newBlock('controls_if_else');
elseBlock.initSvg();
connection.connect(elseBlock.previousConnection);
}
@@ -382,13 +382,13 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
compose: function(containerBlock) {
var clauseBlock = containerBlock.nextConnection.targetBlock();
let clauseBlock = containerBlock.nextConnection.targetBlock();
// Count number of inputs.
this.elseifCount_ = 0;
this.elseCount_ = 0;
var valueConnections = [null];
var statementConnections = [null];
var elseStatementConnection = null;
const valueConnections = [null];
const statementConnections = [null];
let elseStatementConnection = null;
while (clauseBlock && !clauseBlock.isInsertionMarker()) {
switch (clauseBlock.type) {
case 'controls_if_elseif':
@@ -417,24 +417,26 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
saveConnections: function(containerBlock) {
var clauseBlock = containerBlock.nextConnection.targetBlock();
var i = 1;
let clauseBlock = containerBlock.nextConnection.targetBlock();
let i = 1;
while (clauseBlock) {
switch (clauseBlock.type) {
case 'controls_if_elseif':
var inputIf = this.getInput('IF' + i);
var inputDo = this.getInput('DO' + i);
case 'controls_if_elseif': {
const inputIf = this.getInput('IF' + i);
const inputDo = this.getInput('DO' + i);
clauseBlock.valueConnection_ =
inputIf && inputIf.connection.targetConnection;
clauseBlock.statementConnection_ =
inputDo && inputDo.connection.targetConnection;
i++;
break;
case 'controls_if_else':
var inputDo = this.getInput('ELSE');
}
case 'controls_if_else': {
const inputDo = this.getInput('ELSE');
clauseBlock.statementConnection_ =
inputDo && inputDo.connection.targetConnection;
break;
}
default:
throw TypeError('Unknown block type: ' + clauseBlock.type);
}
@@ -447,20 +449,18 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
rebuildShape_: function() {
var valueConnections = [null];
var statementConnections = [null];
var elseStatementConnection = null;
const valueConnections = [null];
const statementConnections = [null];
let elseStatementConnection = null;
if (this.getInput('ELSE')) {
elseStatementConnection = this.getInput('ELSE').connection.targetConnection;
}
var i = 1;
while (this.getInput('IF' + i)) {
var inputIf = this.getInput('IF' + i);
var inputDo = this.getInput('DO' + i);
for (let i = 1; this.getInput('IF' + i); i++) {
const inputIf = this.getInput('IF' + i);
const inputDo = this.getInput('DO' + i);
valueConnections.push(inputIf.connection.targetConnection);
statementConnections.push(inputDo.connection.targetConnection);
i++;
}
this.updateShape_();
this.reconnectChildBlocks_(valueConnections, statementConnections,
@@ -476,14 +476,12 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
if (this.getInput('ELSE')) {
this.removeInput('ELSE');
}
var i = 1;
while (this.getInput('IF' + i)) {
for (let i = 1; this.getInput('IF' + i); i++) {
this.removeInput('IF' + i);
this.removeInput('DO' + i);
i++;
}
// Rebuild block.
for (i = 1; i <= this.elseifCount_; i++) {
for (let i = 1; i <= this.elseifCount_; i++) {
this.appendValueInput('IF' + i)
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSEIF']);
@@ -507,7 +505,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
*/
reconnectChildBlocks_: function(valueConnections, statementConnections,
elseStatementConnection) {
for (var i = 1; i <= this.elseifCount_; i++) {
for (let i = 1; i <= this.elseifCount_; i++) {
Blockly.Mutator.reconnect(valueConnections[i], this, 'IF' + i);
Blockly.Mutator.reconnect(statementConnections[i], this, 'DO' + i);
}
@@ -563,8 +561,8 @@ Blockly.Constants.Logic.LOGIC_COMPARE_ONCHANGE_MIXIN = {
this.prevBlocks_ = [null, null];
}
var blockA = this.getInputTargetBlock('A');
var blockB = this.getInputTargetBlock('B');
const blockA = this.getInputTargetBlock('A');
const blockB = this.getInputTargetBlock('B');
// Disconnect blocks that existed prior to this change if they don't match.
if (blockA && blockB &&
!this.workspace.connectionChecker.doTypeChecks(
@@ -572,7 +570,7 @@ Blockly.Constants.Logic.LOGIC_COMPARE_ONCHANGE_MIXIN = {
// Mismatch between two inputs. Revert the block connections,
// bumping away the newly connected block(s).
Blockly.Events.setGroup(e.group);
var prevA = this.prevBlocks_[0];
const prevA = this.prevBlocks_[0];
if (prevA !== blockA) {
blockA.unplug();
if (prevA && !prevA.isDisposed() && !prevA.isShadow()) {
@@ -580,7 +578,7 @@ Blockly.Constants.Logic.LOGIC_COMPARE_ONCHANGE_MIXIN = {
this.getInput('A').connection.connect(prevA.outputConnection);
}
}
var prevB = this.prevBlocks_[1];
const prevB = this.prevBlocks_[1];
if (prevB !== blockB) {
blockB.unplug();
if (prevB && !prevB.isDisposed() && !prevB.isShadow()) {
@@ -628,13 +626,13 @@ Blockly.Constants.Logic.LOGIC_TERNARY_ONCHANGE_MIXIN = {
* @this {Blockly.Block}
*/
onchange: function(e) {
var blockA = this.getInputTargetBlock('THEN');
var blockB = this.getInputTargetBlock('ELSE');
var parentConnection = this.outputConnection.targetConnection;
const blockA = this.getInputTargetBlock('THEN');
const blockB = this.getInputTargetBlock('ELSE');
const parentConnection = this.outputConnection.targetConnection;
// Disconnect blocks that existed prior to this change if they don't match.
if ((blockA || blockB) && parentConnection) {
for (var i = 0; i < 2; i++) {
var block = (i === 1) ? blockA : blockB;
for (let i = 0; i < 2; i++) {
const block = (i === 1) ? blockA : blockB;
if (block &&
!block.workspace.connectionChecker.doTypeChecks(
block.outputConnection, parentConnection)) {

View File

@@ -251,14 +251,14 @@ Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = {
if (this.isInFlyout) {
return;
}
var variable = this.getField('VAR').getVariable();
var varName = variable.name;
const variable = this.getField('VAR').getVariable();
const varName = variable.name;
if (!this.isCollapsed() && varName !== null) {
var option = {enabled: true};
const option = {enabled: true};
option.text =
Blockly.Msg['VARIABLES_SET_CREATE_GET'].replace('%1', varName);
var xmlField = Blockly.Variables.generateVariableFieldDom(variable);
var xmlBlock = Blockly.utils.xml.createElement('block');
const xmlField = Blockly.Variables.generateVariableFieldDom(variable);
const xmlBlock = Blockly.utils.xml.createElement('block');
xmlBlock.setAttribute('type', 'variables_get');
xmlBlock.appendChild(xmlField);
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
@@ -331,12 +331,12 @@ Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = {
e.type !== Blockly.Events.BLOCK_MOVE) {
return;
}
var enabled = Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN
const enabled = Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN
.getSurroundLoop(this);
this.setWarningText(enabled ? null :
Blockly.Msg['CONTROLS_FLOW_STATEMENTS_WARNING']);
if (!this.isInFlyout) {
var group = Blockly.Events.getGroup();
const group = Blockly.Events.getGroup();
// Makes it so the move and the disable event get undone together.
Blockly.Events.setGroup(e.group);
this.setEnabled(enabled);

View File

@@ -449,8 +449,8 @@ Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
var divisorInput = (this.getFieldValue('PROPERTY') === 'DIVISIBLE_BY');
const container = Blockly.utils.xml.createElement('mutation');
const divisorInput = (this.getFieldValue('PROPERTY') === 'DIVISIBLE_BY');
container.setAttribute('divisor_input', divisorInput);
return container;
},
@@ -461,10 +461,10 @@ Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
domToMutation: function(xmlElement) {
var divisorInput = (xmlElement.getAttribute('divisor_input') === 'true');
const divisorInput = (xmlElement.getAttribute('divisor_input') === 'true');
this.updateShape_(divisorInput);
},
// This block does not need JSO serialization hooks (saveExtraState and
// loadExtraState) because the state of this object is already encoded in the
// dropdown values.
@@ -478,7 +478,7 @@ Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN = {
*/
updateShape_: function(divisorInput) {
// Add or remove a Value Input.
var inputExists = this.getInput('DIVISOR');
const inputExists = this.getInput('DIVISOR');
if (divisorInput) {
if (!inputExists) {
this.appendValueInput('DIVISOR')
@@ -499,7 +499,7 @@ Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN = {
*/
Blockly.Constants.Math.IS_DIVISIBLE_MUTATOR_EXTENSION = function() {
this.getField('PROPERTY').setValidator(function(option) {
var divisorInput = (option === 'DIVISIBLE_BY');
const divisorInput = (option === 'DIVISIBLE_BY');
this.getSourceBlock().updateShape_(divisorInput);
});
};
@@ -542,7 +542,7 @@ Blockly.Constants.Math.LIST_MODES_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('op', this.getFieldValue('OP'));
return container;
},
@@ -555,7 +555,7 @@ Blockly.Constants.Math.LIST_MODES_MUTATOR_MIXIN = {
domToMutation: function(xmlElement) {
this.updateType_(xmlElement.getAttribute('op'));
},
// This block does not need JSO serialization hooks (saveExtraState and
// loadExtraState) because the state of this object is already encoded in the
// dropdown values.

View File

@@ -26,8 +26,8 @@ Blockly.Blocks['procedures_defnoreturn'] = {
* @this {Blockly.Block}
*/
init: function() {
var initName = Blockly.Procedures.findLegalName('', this);
var nameField = new Blockly.FieldTextInput(initName,
const initName = Blockly.Procedures.findLegalName('', this);
const nameField = new Blockly.FieldTextInput(initName,
Blockly.Procedures.rename);
nameField.setSpellcheck(false);
this.appendDummyInput()
@@ -77,7 +77,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
updateParams_: function() {
// Merge the arguments into a human-readable list.
var paramString = '';
let paramString = '';
if (this.arguments_.length) {
paramString = Blockly.Msg['PROCEDURES_BEFORE_PARAMS'] +
' ' + this.arguments_.join(', ');
@@ -100,13 +100,13 @@ Blockly.Blocks['procedures_defnoreturn'] = {
* @this {Blockly.Block}
*/
mutationToDom: function(opt_paramIds) {
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
if (opt_paramIds) {
container.setAttribute('name', this.getFieldValue('NAME'));
}
for (var i = 0; i < this.argumentVarModels_.length; i++) {
var parameter = Blockly.utils.xml.createElement('arg');
var argModel = this.argumentVarModels_[i];
for (let i = 0; i < this.argumentVarModels_.length; i++) {
const parameter = Blockly.utils.xml.createElement('arg');
const argModel = this.argumentVarModels_[i];
parameter.setAttribute('name', argModel.name);
parameter.setAttribute('varid', argModel.getId());
if (opt_paramIds && this.paramIds_) {
@@ -130,12 +130,12 @@ Blockly.Blocks['procedures_defnoreturn'] = {
domToMutation: function(xmlElement) {
this.arguments_ = [];
this.argumentVarModels_ = [];
for (var i = 0, childNode; (childNode = xmlElement.childNodes[i]); i++) {
for (let i = 0, childNode; (childNode = xmlElement.childNodes[i]); i++) {
if (childNode.nodeName.toLowerCase() === 'arg') {
var varName = childNode.getAttribute('name');
var varId = childNode.getAttribute('varid') || childNode.getAttribute('varId');
const varName = childNode.getAttribute('name');
const varId = childNode.getAttribute('varid') || childNode.getAttribute('varId');
this.arguments_.push(varName);
var variable = Blockly.Variables.getOrCreateVariablePackage(
const variable = Blockly.Variables.getOrCreateVariablePackage(
this.workspace, varId, varName, '');
if (variable !== null) {
this.argumentVarModels_.push(variable);
@@ -160,10 +160,10 @@ Blockly.Blocks['procedures_defnoreturn'] = {
if (!this.argumentVarModels_.length && this.hasStatements_) {
return null;
}
var state = Object.create(null);
const state = Object.create(null);
if (this.argumentVarModels_.length) {
state['params'] = [];
for (var i = 0; i < this.argumentVarModels_.length; i++) {
for (let i = 0; i < this.argumentVarModels_.length; i++) {
state['params'].push({
// We don't need to serialize the name, but just in case we decide
// to separate params from variables.
@@ -186,9 +186,9 @@ Blockly.Blocks['procedures_defnoreturn'] = {
this.arguments_ = [];
this.argumentVarModels_ = [];
if (state['params']) {
for (var i = 0; i < state['params'].length; i++) {
var param = state['params'][i];
var variable = Blockly.Variables.getOrCreateVariablePackage(
for (let i = 0; i < state['params'].length; i++) {
const param = state['params'][i];
const variable = Blockly.Variables.getOrCreateVariablePackage(
this.workspace, param['id'], param['name'], '');
this.arguments_.push(variable.name);
this.argumentVarModels_.push(variable);
@@ -217,29 +217,29 @@ Blockly.Blocks['procedures_defnoreturn'] = {
* </block>
*/
var containerBlockNode = Blockly.utils.xml.createElement('block');
const containerBlockNode = Blockly.utils.xml.createElement('block');
containerBlockNode.setAttribute('type', 'procedures_mutatorcontainer');
var statementNode = Blockly.utils.xml.createElement('statement');
const statementNode = Blockly.utils.xml.createElement('statement');
statementNode.setAttribute('name', 'STACK');
containerBlockNode.appendChild(statementNode);
var node = statementNode;
for (var i = 0; i < this.arguments_.length; i++) {
var argBlockNode = Blockly.utils.xml.createElement('block');
let node = statementNode;
for (let i = 0; i < this.arguments_.length; i++) {
const argBlockNode = Blockly.utils.xml.createElement('block');
argBlockNode.setAttribute('type', 'procedures_mutatorarg');
var fieldNode = Blockly.utils.xml.createElement('field');
const fieldNode = Blockly.utils.xml.createElement('field');
fieldNode.setAttribute('name', 'NAME');
var argumentName = Blockly.utils.xml.createTextNode(this.arguments_[i]);
const argumentName = Blockly.utils.xml.createTextNode(this.arguments_[i]);
fieldNode.appendChild(argumentName);
argBlockNode.appendChild(fieldNode);
var nextNode = Blockly.utils.xml.createElement('next');
const nextNode = Blockly.utils.xml.createElement('next');
argBlockNode.appendChild(nextNode);
node.appendChild(argBlockNode);
node = nextNode;
}
var containerBlock = Blockly.Xml.domToBlock(containerBlockNode, workspace);
const containerBlock = Blockly.Xml.domToBlock(containerBlockNode, workspace);
if (this.type === 'procedures_defreturn') {
containerBlock.setFieldValue(this.hasStatements_, 'STATEMENTS');
@@ -261,11 +261,11 @@ Blockly.Blocks['procedures_defnoreturn'] = {
this.arguments_ = [];
this.paramIds_ = [];
this.argumentVarModels_ = [];
var paramBlock = containerBlock.getInputTargetBlock('STACK');
let paramBlock = containerBlock.getInputTargetBlock('STACK');
while (paramBlock && !paramBlock.isInsertionMarker()) {
var varName = paramBlock.getFieldValue('NAME');
const varName = paramBlock.getFieldValue('NAME');
this.arguments_.push(varName);
var variable = this.workspace.getVariable(varName, '');
const variable = this.workspace.getVariable(varName, '');
this.argumentVarModels_.push(variable);
this.paramIds_.push(paramBlock.id);
@@ -276,7 +276,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
Blockly.Procedures.mutateCallers(this);
// Show/hide the statement input.
var hasStatements = containerBlock.getFieldValue('STATEMENTS');
let hasStatements = containerBlock.getFieldValue('STATEMENTS');
if (hasStatements !== null) {
hasStatements = hasStatements === 'TRUE';
if (this.hasStatements_ !== hasStatements) {
@@ -287,10 +287,10 @@ Blockly.Blocks['procedures_defnoreturn'] = {
this.statementConnection_ = null;
} else {
// Save the stack, then disconnect it.
var stackConnection = this.getInput('STACK').connection;
const stackConnection = this.getInput('STACK').connection;
this.statementConnection_ = stackConnection.targetConnection;
if (this.statementConnection_) {
var stackBlock = stackConnection.targetBlock();
const stackBlock = stackConnection.targetBlock();
stackBlock.unplug();
stackBlock.bumpNeighbours();
}
@@ -337,16 +337,16 @@ Blockly.Blocks['procedures_defnoreturn'] = {
* @this {Blockly.Block}
*/
renameVarById: function(oldId, newId) {
var oldVariable = this.workspace.getVariableById(oldId);
const oldVariable = this.workspace.getVariableById(oldId);
if (oldVariable.type !== '') {
// Procedure arguments always have the empty type.
return;
}
var oldName = oldVariable.name;
var newVar = this.workspace.getVariableById(newId);
const oldName = oldVariable.name;
const newVar = this.workspace.getVariableById(newId);
var change = false;
for (var i = 0; i < this.argumentVarModels_.length; i++) {
let change = false;
for (let i = 0; i < this.argumentVarModels_.length; i++) {
if (this.argumentVarModels_[i].getId() === oldId) {
this.arguments_[i] = newVar.name;
this.argumentVarModels_[i] = newVar;
@@ -367,11 +367,12 @@ Blockly.Blocks['procedures_defnoreturn'] = {
* @this {Blockly.Block}
*/
updateVarName: function(variable) {
var newName = variable.name;
var change = false;
for (var i = 0; i < this.argumentVarModels_.length; i++) {
const newName = variable.name;
let change = false;
let oldName;
for (let i = 0; i < this.argumentVarModels_.length; i++) {
if (this.argumentVarModels_[i].getId() === variable.getId()) {
var oldName = this.arguments_[i];
oldName = this.arguments_[i];
this.arguments_[i] = newName;
change = true;
}
@@ -392,8 +393,8 @@ Blockly.Blocks['procedures_defnoreturn'] = {
this.updateParams_();
// Update the mutator's variables if the mutator is open.
if (this.mutator && this.mutator.isVisible()) {
var blocks = this.mutator.workspace_.getAllBlocks(false);
for (var i = 0, block; (block = blocks[i]); i++) {
const blocks = this.mutator.workspace_.getAllBlocks(false);
for (let i = 0, block; (block = blocks[i]); i++) {
if (block.type === 'procedures_mutatorarg' &&
Blockly.Names.equals(oldName, block.getFieldValue('NAME'))) {
block.setFieldValue(newName, 'NAME');
@@ -411,17 +412,17 @@ Blockly.Blocks['procedures_defnoreturn'] = {
return;
}
// Add option to create caller.
var option = {enabled: true};
var name = this.getFieldValue('NAME');
const option = {enabled: true};
const name = this.getFieldValue('NAME');
option.text = Blockly.Msg['PROCEDURES_CREATE_DO'].replace('%1', name);
var xmlMutation = Blockly.utils.xml.createElement('mutation');
const xmlMutation = Blockly.utils.xml.createElement('mutation');
xmlMutation.setAttribute('name', name);
for (var i = 0; i < this.arguments_.length; i++) {
var xmlArg = Blockly.utils.xml.createElement('arg');
for (let i = 0; i < this.arguments_.length; i++) {
const xmlArg = Blockly.utils.xml.createElement('arg');
xmlArg.setAttribute('name', this.arguments_[i]);
xmlMutation.appendChild(xmlArg);
}
var xmlBlock = Blockly.utils.xml.createElement('block');
const xmlBlock = Blockly.utils.xml.createElement('block');
xmlBlock.setAttribute('type', this.callType_);
xmlBlock.appendChild(xmlMutation);
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
@@ -429,14 +430,14 @@ Blockly.Blocks['procedures_defnoreturn'] = {
// Add options to create getters for each parameter.
if (!this.isCollapsed()) {
for (var i = 0; i < this.argumentVarModels_.length; i++) {
var argOption = {enabled: true};
var argVar = this.argumentVarModels_[i];
for (let i = 0; i < this.argumentVarModels_.length; i++) {
const argOption = {enabled: true};
const argVar = this.argumentVarModels_[i];
argOption.text = Blockly.Msg['VARIABLES_SET_CREATE_GET']
.replace('%1', argVar.name);
var argXmlField = Blockly.Variables.generateVariableFieldDom(argVar);
var argXmlBlock = Blockly.utils.xml.createElement('block');
const argXmlField = Blockly.Variables.generateVariableFieldDom(argVar);
const argXmlBlock = Blockly.utils.xml.createElement('block');
argXmlBlock.setAttribute('type', 'variables_get');
argXmlBlock.appendChild(argXmlField);
argOption.callback =
@@ -454,8 +455,8 @@ Blockly.Blocks['procedures_defreturn'] = {
* @this {Blockly.Block}
*/
init: function() {
var initName = Blockly.Procedures.findLegalName('', this);
var nameField = new Blockly.FieldTextInput(initName,
const initName = Blockly.Procedures.findLegalName('', this);
const nameField = new Blockly.FieldTextInput(initName,
Blockly.Procedures.rename);
nameField.setSpellcheck(false);
this.appendDummyInput()
@@ -532,12 +533,12 @@ Blockly.Blocks['procedures_mutatorarg'] = {
* @this {Blockly.Block}
*/
init: function() {
var field = new Blockly.FieldTextInput(
const field = new Blockly.FieldTextInput(
Blockly.Procedures.DEFAULT_ARG, this.validator_);
// Hack: override showEditor to do just a little bit more work.
// We don't have a good place to hook into the start of a text edit.
field.oldShowEditorFn_ = field.showEditor_;
var newShowEditorFn = function() {
const newShowEditorFn = function() {
this.createdVariables_ = [];
this.oldShowEditorFn_();
};
@@ -572,24 +573,24 @@ Blockly.Blocks['procedures_mutatorarg'] = {
* @this {Blockly.FieldTextInput}
*/
validator_: function(varName) {
var sourceBlock = this.getSourceBlock();
var outerWs = Blockly.Mutator.findParentWs(sourceBlock.workspace);
const sourceBlock = this.getSourceBlock();
const outerWs = Blockly.Mutator.findParentWs(sourceBlock.workspace);
varName = varName.replace(/[\s\xa0]+/g, ' ').replace(/^ | $/g, '');
if (!varName) {
return null;
}
// Prevents duplicate parameter names in functions
var workspace = sourceBlock.workspace.targetWorkspace ||
const workspace = sourceBlock.workspace.targetWorkspace ||
sourceBlock.workspace;
var blocks = workspace.getAllBlocks(false);
var caselessName = varName.toLowerCase();
for (var i = 0; i < blocks.length; i++) {
const blocks = workspace.getAllBlocks(false);
const caselessName = varName.toLowerCase();
for (let i = 0; i < blocks.length; i++) {
if (blocks[i].id === this.getSourceBlock().id) {
continue;
}
// Other blocks values may not be set yet when this is loaded.
var otherVar = blocks[i].getFieldValue('NAME');
const otherVar = blocks[i].getFieldValue('NAME');
if (otherVar && otherVar.toLowerCase() === caselessName) {
return null;
}
@@ -601,7 +602,7 @@ Blockly.Blocks['procedures_mutatorarg'] = {
return varName;
}
var model = outerWs.getVariable(varName, '');
let model = outerWs.getVariable(varName, '');
if (model && model.name !== varName) {
// Rename the variable (case change)
outerWs.renameVariableById(model.getId(), varName);
@@ -624,12 +625,12 @@ Blockly.Blocks['procedures_mutatorarg'] = {
* @this {Blockly.FieldTextInput}
*/
deleteIntermediateVars_: function(newText) {
var outerWs = Blockly.Mutator.findParentWs(this.getSourceBlock().workspace);
const outerWs = Blockly.Mutator.findParentWs(this.getSourceBlock().workspace);
if (!outerWs) {
return;
}
for (var i = 0; i < this.createdVariables_.length; i++) {
var model = this.createdVariables_[i];
for (let i = 0; i < this.createdVariables_.length; i++) {
const model = this.createdVariables_[i];
if (model.name !== newText) {
outerWs.deleteVariableById(model.getId());
}
@@ -676,7 +677,7 @@ Blockly.Blocks['procedures_callnoreturn'] = {
renameProcedure: function(oldName, newName) {
if (Blockly.Names.equals(oldName, this.getProcedureCall())) {
this.setFieldValue(newName, 'NAME');
var baseMsg = this.outputConnection ?
const baseMsg = this.outputConnection ?
Blockly.Msg['PROCEDURES_CALLRETURN_TOOLTIP'] :
Blockly.Msg['PROCEDURES_CALLNORETURN_TOOLTIP'];
this.setTooltip(baseMsg.replace('%1', newName));
@@ -701,9 +702,9 @@ Blockly.Blocks['procedures_callnoreturn'] = {
// Existing param IDs.
// Note that quarkConnections_ may include IDs that no longer exist, but
// which might reappear if a param is reattached in the mutator.
var defBlock = Blockly.Procedures.getDefinition(this.getProcedureCall(),
const defBlock = Blockly.Procedures.getDefinition(this.getProcedureCall(),
this.workspace);
var mutatorOpen = defBlock && defBlock.mutator &&
const mutatorOpen = defBlock && defBlock.mutator &&
defBlock.mutator.isVisible();
if (!mutatorOpen) {
this.quarkConnections_ = {};
@@ -730,13 +731,13 @@ Blockly.Blocks['procedures_callnoreturn'] = {
this.quarkIds_ = [];
}
// Switch off rendering while the block is rebuilt.
var savedRendered = this.rendered;
const savedRendered = this.rendered;
this.rendered = false;
// Update the quarkConnections_ with existing connections.
for (var i = 0; i < this.arguments_.length; i++) {
var input = this.getInput('ARG' + i);
for (let i = 0; i < this.arguments_.length; i++) {
const input = this.getInput('ARG' + i);
if (input) {
var connection = input.connection.targetConnection;
const connection = input.connection.targetConnection;
this.quarkConnections_[this.quarkIds_[i]] = connection;
if (mutatorOpen && connection &&
paramIds.indexOf(this.quarkIds_[i]) === -1) {
@@ -750,8 +751,8 @@ Blockly.Blocks['procedures_callnoreturn'] = {
this.arguments_ = [].concat(paramNames);
// And rebuild the argument model list.
this.argumentVarModels_ = [];
for (var i = 0; i < this.arguments_.length; i++) {
var variable = Blockly.Variables.getOrCreateVariablePackage(
for (let i = 0; i < this.arguments_.length; i++) {
const variable = Blockly.Variables.getOrCreateVariablePackage(
this.workspace, null, this.arguments_[i], '');
this.argumentVarModels_.push(variable);
}
@@ -760,10 +761,10 @@ Blockly.Blocks['procedures_callnoreturn'] = {
this.quarkIds_ = paramIds;
// Reconnect any child blocks.
if (this.quarkIds_) {
for (var i = 0; i < this.arguments_.length; i++) {
var quarkId = this.quarkIds_[i];
for (let i = 0; i < this.arguments_.length; i++) {
const quarkId = this.quarkIds_[i];
if (quarkId in this.quarkConnections_) {
var connection = this.quarkConnections_[quarkId];
const connection = this.quarkConnections_[quarkId];
if (!Blockly.Mutator.reconnect(connection, this, 'ARG' + i)) {
// Block no longer exists or has been attached elsewhere.
delete this.quarkConnections_[quarkId];
@@ -783,34 +784,33 @@ Blockly.Blocks['procedures_callnoreturn'] = {
* @this {Blockly.Block}
*/
updateShape_: function() {
for (var i = 0; i < this.arguments_.length; i++) {
var field = this.getField('ARGNAME' + i);
if (field) {
for (let i = 0; i < this.arguments_.length; i++) {
const argField = this.getField('ARGNAME' + i);
if (argField) {
// Ensure argument name is up to date.
// The argument name field is deterministic based on the mutation,
// no need to fire a change event.
Blockly.Events.disable();
try {
field.setValue(this.arguments_[i]);
argField.setValue(this.arguments_[i]);
} finally {
Blockly.Events.enable();
}
} else {
// Add new input.
field = new Blockly.FieldLabel(this.arguments_[i]);
var input = this.appendValueInput('ARG' + i)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(field, 'ARGNAME' + i);
const newField = new Blockly.FieldLabel(this.arguments_[i]);
const input = this.appendValueInput('ARG' + i)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(newField, 'ARGNAME' + i);
input.init();
}
}
// Remove deleted inputs.
while (this.getInput('ARG' + i)) {
for (let i = this.itemCount_; this.getInput('ARG' + i); i++) {
this.removeInput('ARG' + i);
i++;
}
// Add 'with:' if there are parameters, remove otherwise.
var topRow = this.getInput('TOPROW');
const topRow = this.getInput('TOPROW');
if (topRow) {
if (this.arguments_.length) {
if (!this.getField('WITH')) {
@@ -831,10 +831,10 @@ Blockly.Blocks['procedures_callnoreturn'] = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('name', this.getProcedureCall());
for (var i = 0; i < this.arguments_.length; i++) {
var parameter = Blockly.utils.xml.createElement('arg');
for (let i = 0; i < this.arguments_.length; i++) {
const parameter = Blockly.utils.xml.createElement('arg');
parameter.setAttribute('name', this.arguments_[i]);
container.appendChild(parameter);
}
@@ -847,11 +847,11 @@ Blockly.Blocks['procedures_callnoreturn'] = {
* @this {Blockly.Block}
*/
domToMutation: function(xmlElement) {
var name = xmlElement.getAttribute('name');
const name = xmlElement.getAttribute('name');
this.renameProcedure(this.getProcedureCall(), name);
var args = [];
var paramIds = [];
for (var i = 0, childNode; (childNode = xmlElement.childNodes[i]); i++) {
const args = [];
const paramIds = [];
for (let i = 0, childNode; (childNode = xmlElement.childNodes[i]); i++) {
if (childNode.nodeName.toLowerCase() === 'arg') {
args.push(childNode.getAttribute('name'));
paramIds.push(childNode.getAttribute('paramId'));
@@ -865,7 +865,7 @@ Blockly.Blocks['procedures_callnoreturn'] = {
* this block, ie the params and procedure name.
*/
saveExtraState: function() {
var state = Object.create(null);
const state = Object.create(null);
state['name'] = this.getProcedureCall();
if (this.arguments_.length) {
state['params'] = this.arguments_;
@@ -923,8 +923,8 @@ Blockly.Blocks['procedures_callnoreturn'] = {
// Look for the case where a procedure call was created (usually through
// paste) and there is no matching definition. In this case, create
// an empty definition block with the correct signature.
var name = this.getProcedureCall();
var def = Blockly.Procedures.getDefinition(name, this.workspace);
const name = this.getProcedureCall();
let def = Blockly.Procedures.getDefinition(name, this.workspace);
if (def && (def.type !== this.defType_ ||
JSON.stringify(def.getVars()) !== JSON.stringify(this.arguments_))) {
// The signatures don't match.
@@ -943,19 +943,19 @@ Blockly.Blocks['procedures_callnoreturn'] = {
* </block>
* </xml>
*/
var xml = Blockly.utils.xml.createElement('xml');
var block = Blockly.utils.xml.createElement('block');
const xml = Blockly.utils.xml.createElement('xml');
const block = Blockly.utils.xml.createElement('block');
block.setAttribute('type', this.defType_);
var xy = this.getRelativeToSurfaceXY();
var x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1);
var y = xy.y + Blockly.SNAP_RADIUS * 2;
const xy = this.getRelativeToSurfaceXY();
const x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1);
const y = xy.y + Blockly.SNAP_RADIUS * 2;
block.setAttribute('x', x);
block.setAttribute('y', y);
var mutation = this.mutationToDom();
const mutation = this.mutationToDom();
block.appendChild(mutation);
var field = Blockly.utils.xml.createElement('field');
const field = Blockly.utils.xml.createElement('field');
field.setAttribute('name', 'NAME');
var callName = this.getProcedureCall();
let callName = this.getProcedureCall();
if (!callName) {
// Rename if name is empty string.
callName = Blockly.Procedures.findLegalName('', this);
@@ -971,19 +971,19 @@ Blockly.Blocks['procedures_callnoreturn'] = {
// Look for the case where a procedure definition has been deleted,
// leaving this block (a procedure call) orphaned. In this case, delete
// the orphan.
var name = this.getProcedureCall();
var def = Blockly.Procedures.getDefinition(name, this.workspace);
const name = this.getProcedureCall();
const def = Blockly.Procedures.getDefinition(name, this.workspace);
if (!def) {
Blockly.Events.setGroup(event.group);
this.dispose(true);
Blockly.Events.setGroup(false);
}
} else if (event.type === Blockly.Events.CHANGE && event.element === 'disabled') {
var name = this.getProcedureCall();
var def = Blockly.Procedures.getDefinition(name, this.workspace);
const name = this.getProcedureCall();
const def = Blockly.Procedures.getDefinition(name, this.workspace);
if (def && def.id === event.blockId) {
// in most cases the old group should be ''
var oldGroup = Blockly.Events.getGroup();
const oldGroup = Blockly.Events.getGroup();
if (oldGroup) {
// This should only be possible programmatically and may indicate a problem
// with event grouping. If you see this message please investigate. If the
@@ -1013,12 +1013,12 @@ Blockly.Blocks['procedures_callnoreturn'] = {
return;
}
var option = {enabled: true};
const option = {enabled: true};
option.text = Blockly.Msg['PROCEDURES_HIGHLIGHT_DEF'];
var name = this.getProcedureCall();
var workspace = this.workspace;
const name = this.getProcedureCall();
const workspace = this.workspace;
option.callback = function() {
var def = Blockly.Procedures.getDefinition(name, workspace);
const def = Blockly.Procedures.getDefinition(name, workspace);
if (def) {
workspace.centerOnBlock(def.id);
def.select();
@@ -1090,7 +1090,7 @@ Blockly.Blocks['procedures_ifreturn'] = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('value', Number(this.hasReturnValue_));
return container;
},
@@ -1100,7 +1100,7 @@ Blockly.Blocks['procedures_ifreturn'] = {
* @this {Blockly.Block}
*/
domToMutation: function(xmlElement) {
var value = xmlElement.getAttribute('value');
const value = xmlElement.getAttribute('value');
this.hasReturnValue_ = (value === '1');
if (!this.hasReturnValue_) {
this.removeInput('VALUE');
@@ -1124,9 +1124,9 @@ Blockly.Blocks['procedures_ifreturn'] = {
if (this.workspace.isDragging && this.workspace.isDragging()) {
return; // Don't change state at the start of a drag.
}
var legal = false;
let legal = false;
// Is the block nested in a procedure?
var block = this;
let block = this;
do {
if (this.FUNCTION_TYPES.indexOf(block.type) !== -1) {
legal = true;

View File

@@ -264,10 +264,10 @@ Blockly.Blocks['text_getSubstring'] = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
var isAt1 = this.getInput('AT1').type === Blockly.INPUT_VALUE;
const container = Blockly.utils.xml.createElement('mutation');
const isAt1 = this.getInput('AT1').type === Blockly.INPUT_VALUE;
container.setAttribute('at1', isAt1);
var isAt2 = this.getInput('AT2').type === Blockly.INPUT_VALUE;
const isAt2 = this.getInput('AT2').type === Blockly.INPUT_VALUE;
container.setAttribute('at2', isAt2);
return container;
},
@@ -278,12 +278,12 @@ Blockly.Blocks['text_getSubstring'] = {
* @this {Blockly.Block}
*/
domToMutation: function(xmlElement) {
var isAt1 = (xmlElement.getAttribute('at1') === 'true');
var isAt2 = (xmlElement.getAttribute('at2') === 'true');
const isAt1 = (xmlElement.getAttribute('at1') === 'true');
const isAt2 = (xmlElement.getAttribute('at2') === 'true');
this.updateAt_(1, isAt1);
this.updateAt_(2, isAt2);
},
// This block does not need JSO serialization hooks (saveExtraState and
// loadExtraState) because the state of this object is already encoded in the
// dropdown values.
@@ -318,13 +318,13 @@ Blockly.Blocks['text_getSubstring'] = {
this.appendDummyInput('TAIL')
.appendField(Blockly.Msg['TEXT_GET_SUBSTRING_TAIL']);
}
var menu = new Blockly.FieldDropdown(this['WHERE_OPTIONS_' + n],
const menu = new Blockly.FieldDropdown(this['WHERE_OPTIONS_' + n],
function(value) {
var newAt = (value === 'FROM_START') || (value === 'FROM_END');
const newAt = (value === 'FROM_START') || (value === 'FROM_END');
// The 'isAt' variable is available due to this function being a
// closure.
if (newAt !== isAt) {
var block = this.getSourceBlock();
const block = this.getSourceBlock();
block.updateAt_(n, newAt);
// This menu has been destroyed and replaced.
// Update the replacement.
@@ -351,7 +351,7 @@ Blockly.Blocks['text_changeCase'] = {
* @this {Blockly.Block}
*/
init: function() {
var OPERATORS = [
const OPERATORS = [
[Blockly.Msg['TEXT_CHANGECASE_OPERATOR_UPPERCASE'], 'UPPERCASE'],
[Blockly.Msg['TEXT_CHANGECASE_OPERATOR_LOWERCASE'], 'LOWERCASE'],
[Blockly.Msg['TEXT_CHANGECASE_OPERATOR_TITLECASE'], 'TITLECASE'],
@@ -372,7 +372,7 @@ Blockly.Blocks['text_trim'] = {
* @this {Blockly.Block}
*/
init: function() {
var OPERATORS = [
const OPERATORS = [
[Blockly.Msg['TEXT_TRIM_OPERATOR_BOTH'], 'BOTH'],
[Blockly.Msg['TEXT_TRIM_OPERATOR_LEFT'], 'LEFT'],
[Blockly.Msg['TEXT_TRIM_OPERATOR_RIGHT'], 'RIGHT'],
@@ -416,15 +416,15 @@ Blockly.Blocks['text_prompt_ext'] = {
* @this {Blockly.Block}
*/
init: function() {
var TYPES = [
const TYPES = [
[Blockly.Msg['TEXT_PROMPT_TYPE_TEXT'], 'TEXT'],
[Blockly.Msg['TEXT_PROMPT_TYPE_NUMBER'], 'NUMBER'],
];
this.setHelpUrl(Blockly.Msg['TEXT_PROMPT_HELPURL']);
this.setStyle('text_blocks');
// Assign 'this' to a variable for use in the closures below.
var thisBlock = this;
var dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) {
const thisBlock = this;
const dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) {
thisBlock.updateType_(newOp);
});
this.appendValueInput('TEXT')
@@ -452,7 +452,7 @@ Blockly.Blocks['text_prompt_ext'] = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('type', this.getFieldValue('TYPE'));
return container;
},
@@ -465,7 +465,7 @@ Blockly.Blocks['text_prompt_ext'] = {
domToMutation: function(xmlElement) {
this.updateType_(xmlElement.getAttribute('type'));
},
// This block does not need JSO serialization hooks (saveExtraState and
// loadExtraState) because the state of this object is already encoded in the
// dropdown values.
@@ -480,16 +480,16 @@ Blockly.Blocks['text_prompt'] = {
*/
init: function() {
this.mixin(Blockly.Constants.Text.QUOTE_IMAGE_MIXIN);
var TYPES = [
const TYPES = [
[Blockly.Msg['TEXT_PROMPT_TYPE_TEXT'], 'TEXT'],
[Blockly.Msg['TEXT_PROMPT_TYPE_NUMBER'], 'NUMBER'],
];
// Assign 'this' to a variable for use in the closures below.
var thisBlock = this;
const thisBlock = this;
this.setHelpUrl(Blockly.Msg['TEXT_PROMPT_HELPURL']);
this.setStyle('text_blocks');
var dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) {
const dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) {
thisBlock.updateType_(newOp);
});
this.appendDummyInput()
@@ -640,8 +640,8 @@ Blockly.Constants.Text.QUOTE_IMAGE_MIXIN = {
* @this {Blockly.Block}
*/
quoteField_: function(fieldName) {
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 (fieldName === field.name) {
input.insertFieldAt(j, this.newQuote_(true));
input.insertFieldAt(j + 2, this.newQuote_(false));
@@ -661,8 +661,8 @@ Blockly.Constants.Text.QUOTE_IMAGE_MIXIN = {
* @this {Blockly.Block}
*/
newQuote_: function(open) {
var isLeft = this.RTL ? !open : open;
var dataUri = isLeft ?
const isLeft = this.RTL ? !open : open;
const dataUri = isLeft ?
this.QUOTE_IMAGE_LEFT_DATAURI :
this.QUOTE_IMAGE_RIGHT_DATAURI;
return new Blockly.FieldImage(
@@ -696,7 +696,7 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('items', this.itemCount_);
return container;
},
@@ -734,11 +734,11 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
decompose: function(workspace) {
var containerBlock = workspace.newBlock('text_create_join_container');
const containerBlock = workspace.newBlock('text_create_join_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('text_create_join_item');
let connection = containerBlock.getInput('STACK').connection;
for (let i = 0; i < this.itemCount_; i++) {
const itemBlock = workspace.newBlock('text_create_join_item');
itemBlock.initSvg();
connection.connect(itemBlock.previousConnection);
connection = itemBlock.nextConnection;
@@ -751,17 +751,17 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
compose: function(containerBlock) {
var itemBlock = containerBlock.getInputTargetBlock('STACK');
let itemBlock = containerBlock.getInputTargetBlock('STACK');
// Count number of inputs.
var connections = [];
const connections = [];
while (itemBlock && !itemBlock.isInsertionMarker()) {
connections.push(itemBlock.valueConnection_);
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
}
// Disconnect any children that don't belong.
for (var i = 0; i < this.itemCount_; i++) {
var connection = this.getInput('ADD' + i).connection.targetConnection;
for (let i = 0; i < this.itemCount_; i++) {
const connection = this.getInput('ADD' + i).connection.targetConnection;
if (connection && connections.indexOf(connection) === -1) {
connection.disconnect();
}
@@ -769,7 +769,7 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = {
this.itemCount_ = connections.length;
this.updateShape_();
// Reconnect any child blocks.
for (var i = 0; i < this.itemCount_; i++) {
for (let i = 0; i < this.itemCount_; i++) {
Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
}
},
@@ -779,14 +779,14 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
saveConnections: function(containerBlock) {
var itemBlock = containerBlock.getInputTargetBlock('STACK');
var i = 0;
let itemBlock = containerBlock.getInputTargetBlock('STACK');
let i = 0;
while (itemBlock) {
var input = this.getInput('ADD' + i);
const input = this.getInput('ADD' + i);
itemBlock.valueConnection_ = input && input.connection.targetConnection;
itemBlock =
itemBlock.nextConnection && itemBlock.nextConnection.targetBlock();
i++;
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
}
},
/**
@@ -803,9 +803,9 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = {
.appendField(this.newQuote_(false));
}
// Add new inputs.
for (var i = 0; i < this.itemCount_; i++) {
for (let i = 0; i < this.itemCount_; i++) {
if (!this.getInput('ADD' + i)) {
var input = this.appendValueInput('ADD' + i)
const input = this.appendValueInput('ADD' + i)
.setAlign(Blockly.ALIGN_RIGHT);
if (i === 0) {
input.appendField(Blockly.Msg['TEXT_JOIN_TITLE_CREATEWITH']);
@@ -813,9 +813,8 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = {
}
}
// Remove deleted inputs.
while (this.getInput('ADD' + i)) {
for (let i = this.itemCount_; this.getInput('ADD' + i); i++) {
this.removeInput('ADD' + i);
i++;
}
},
};
@@ -845,7 +844,7 @@ Blockly.Extensions.register('text_append_tooltip',
*/
Blockly.Constants.Text.TEXT_INDEXOF_TOOLTIP_EXTENSION = function() {
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
const thisBlock = this;
this.setTooltip(function() {
return Blockly.Msg['TEXT_INDEXOF_TOOLTIP'].replace('%1',
thisBlock.workspace.options.oneBasedIndex ? '0' : '-1');
@@ -866,7 +865,7 @@ Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
mutationToDom: function() {
var container = Blockly.utils.xml.createElement('mutation');
const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('at', !!this.isAt_);
return container;
},
@@ -879,10 +878,10 @@ Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN = {
domToMutation: function(xmlElement) {
// Note: Until January 2013 this block did not have mutations,
// so 'at' defaults to true.
var isAt = (xmlElement.getAttribute('at') !== 'false');
const isAt = (xmlElement.getAttribute('at') !== 'false');
this.updateAt_(isAt);
},
// This block does not need JSO serialization hooks (saveExtraState and
// loadExtraState) because the state of this object is already encoded in the
// dropdown values.
@@ -921,22 +920,22 @@ Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN = {
* @this {Blockly.Block}
*/
Blockly.Constants.Text.TEXT_CHARAT_EXTENSION = function() {
var dropdown = this.getField('WHERE');
const dropdown = this.getField('WHERE');
dropdown.setValidator(function(value) {
var newAt = (value === 'FROM_START') || (value === 'FROM_END');
const newAt = (value === 'FROM_START') || (value === 'FROM_END');
if (newAt !== this.isAt_) {
var block = this.getSourceBlock();
const block = this.getSourceBlock();
block.updateAt_(newAt);
}
});
this.updateAt_(true);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
const thisBlock = this;
this.setTooltip(function() {
var where = thisBlock.getFieldValue('WHERE');
var tooltip = Blockly.Msg['TEXT_CHARAT_TOOLTIP'];
const where = thisBlock.getFieldValue('WHERE');
let tooltip = Blockly.Msg['TEXT_CHARAT_TOOLTIP'];
if (where === 'FROM_START' || where === 'FROM_END') {
var msg = (where === 'FROM_START') ?
const msg = (where === 'FROM_START') ?
Blockly.Msg['LISTS_INDEX_FROM_START_TOOLTIP'] :
Blockly.Msg['LISTS_INDEX_FROM_END_TOOLTIP'];
if (msg) {

View File

@@ -87,22 +87,24 @@ Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = {
*/
customContextMenu: function(options) {
if (!this.isInFlyout) {
let opposite_type;
let contextMenuMsg;
// Getter blocks have the option to create a setter block, and vice versa.
if (this.type === 'variables_get') {
var opposite_type = 'variables_set';
var contextMenuMsg = Blockly.Msg['VARIABLES_GET_CREATE_SET'];
opposite_type = 'variables_set';
contextMenuMsg = Blockly.Msg['VARIABLES_GET_CREATE_SET'];
} else {
var opposite_type = 'variables_get';
var contextMenuMsg = Blockly.Msg['VARIABLES_SET_CREATE_GET'];
opposite_type = 'variables_get';
contextMenuMsg = Blockly.Msg['VARIABLES_SET_CREATE_GET'];
}
var option = {enabled: this.workspace.remainingCapacity() > 0};
var name = this.getField('VAR').getText();
const option = {enabled: this.workspace.remainingCapacity() > 0};
const name = this.getField('VAR').getText();
option.text = contextMenuMsg.replace('%1', name);
var xmlField = Blockly.utils.xml.createElement('field');
const xmlField = Blockly.utils.xml.createElement('field');
xmlField.setAttribute('name', 'VAR');
xmlField.appendChild(Blockly.utils.xml.createTextNode(name));
var xmlBlock = Blockly.utils.xml.createElement('block');
const xmlBlock = Blockly.utils.xml.createElement('block');
xmlBlock.setAttribute('type', opposite_type);
xmlBlock.appendChild(xmlField);
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
@@ -110,13 +112,13 @@ Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = {
// Getter blocks have the option to rename or delete that variable.
} else {
if (this.type === 'variables_get' || this.type === 'variables_get_reporter') {
var renameOption = {
const renameOption = {
text: Blockly.Msg.RENAME_VARIABLE,
enabled: true,
callback: Blockly.Constants.Variables.RENAME_OPTION_CALLBACK_FACTORY(this),
};
var name = this.getField('VAR').getText();
var deleteOption = {
const name = this.getField('VAR').getText();
const deleteOption = {
text: Blockly.Msg.DELETE_VARIABLE.replace('%1', name),
enabled: true,
callback: Blockly.Constants.Variables.DELETE_OPTION_CALLBACK_FACTORY(this),
@@ -136,8 +138,8 @@ Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = {
*/
Blockly.Constants.Variables.RENAME_OPTION_CALLBACK_FACTORY = function(block) {
return function() {
var workspace = block.workspace;
var variable = block.getField('VAR').getVariable();
const workspace = block.workspace;
const variable = block.getField('VAR').getVariable();
Blockly.Variables.renameVariable(workspace, variable);
};
};
@@ -150,8 +152,8 @@ Blockly.Constants.Variables.RENAME_OPTION_CALLBACK_FACTORY = function(block) {
*/
Blockly.Constants.Variables.DELETE_OPTION_CALLBACK_FACTORY = function(block) {
return function() {
var workspace = block.workspace;
var variable = block.getField('VAR').getVariable();
const workspace = block.workspace;
const variable = block.getField('VAR').getVariable();
workspace.deleteVariableById(variable.getId());
workspace.refreshToolboxSelection();
};

View File

@@ -84,11 +84,11 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
customContextMenu: function(options) {
// Getter blocks have the option to create a setter block, and vice versa.
if (!this.isInFlyout) {
var opposite_type;
var contextMenuMsg;
var id = this.getFieldValue('VAR');
var variableModel = this.workspace.getVariableById(id);
var varType = variableModel.type;
let opposite_type;
let contextMenuMsg;
const id = this.getFieldValue('VAR');
const variableModel = this.workspace.getVariableById(id);
const varType = variableModel.type;
if (this.type === 'variables_get_dynamic') {
opposite_type = 'variables_set_dynamic';
contextMenuMsg = Blockly.Msg['VARIABLES_GET_CREATE_SET'];
@@ -97,14 +97,14 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
contextMenuMsg = Blockly.Msg['VARIABLES_SET_CREATE_GET'];
}
var option = {enabled: this.workspace.remainingCapacity() > 0};
var name = this.getField('VAR').getText();
const option = {enabled: this.workspace.remainingCapacity() > 0};
const name = this.getField('VAR').getText();
option.text = contextMenuMsg.replace('%1', name);
var xmlField = Blockly.utils.xml.createElement('field');
const xmlField = Blockly.utils.xml.createElement('field');
xmlField.setAttribute('name', 'VAR');
xmlField.setAttribute('variabletype', varType);
xmlField.appendChild(Blockly.utils.xml.createTextNode(name));
var xmlBlock = Blockly.utils.xml.createElement('block');
const xmlBlock = Blockly.utils.xml.createElement('block');
xmlBlock.setAttribute('type', opposite_type);
xmlBlock.appendChild(xmlField);
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
@@ -112,13 +112,13 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
} else {
if (this.type === 'variables_get_dynamic' ||
this.type === 'variables_get_reporter_dynamic') {
var renameOption = {
const renameOption = {
text: Blockly.Msg.RENAME_VARIABLE,
enabled: true,
callback: Blockly.Constants.Variables.RENAME_OPTION_CALLBACK_FACTORY(this),
};
var name = this.getField('VAR').getText();
var deleteOption = {
const name = this.getField('VAR').getText();
const deleteOption = {
text: Blockly.Msg.DELETE_VARIABLE.replace('%1', name),
enabled: true,
callback: Blockly.Constants.Variables.DELETE_OPTION_CALLBACK_FACTORY(this),
@@ -135,8 +135,8 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
* @this {Blockly.Block}
*/
onchange: function(_e) {
var id = this.getFieldValue('VAR');
var variableModel = Blockly.Variables.getVariable(this.workspace, id);
const id = this.getFieldValue('VAR');
const variableModel = Blockly.Variables.getVariable(this.workspace, id);
if (this.type === 'variables_get_dynamic') {
this.outputConnection.setCheck(variableModel.type);
} else {
@@ -153,8 +153,8 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
*/
Blockly.Constants.VariablesDynamic.RENAME_OPTION_CALLBACK_FACTORY = function(block) {
return function() {
var workspace = block.workspace;
var variable = block.getField('VAR').getVariable();
const workspace = block.workspace;
const variable = block.getField('VAR').getVariable();
Blockly.Variables.renameVariable(workspace, variable);
};
};
@@ -167,8 +167,8 @@ Blockly.Constants.VariablesDynamic.RENAME_OPTION_CALLBACK_FACTORY = function(blo
*/
Blockly.Constants.VariablesDynamic.DELETE_OPTION_CALLBACK_FACTORY = function(block) {
return function() {
var workspace = block.workspace;
var variable = block.getField('VAR').getVariable();
const workspace = block.workspace;
const variable = block.getField('VAR').getVariable();
workspace.deleteVariableById(variable.getId());
workspace.refreshToolboxSelection();
};