mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
chore: update lua block generators to const and let (#5662)
This commit is contained in:
@@ -16,9 +16,9 @@ goog.require('Blockly.Lua');
|
||||
|
||||
Blockly.Lua['procedures_defreturn'] = function(block) {
|
||||
// Define a procedure with a return value.
|
||||
var funcName = Blockly.Lua.nameDB_.getName(
|
||||
const funcName = Blockly.Lua.nameDB_.getName(
|
||||
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
|
||||
var xfix1 = '';
|
||||
let xfix1 = '';
|
||||
if (Blockly.Lua.STATEMENT_PREFIX) {
|
||||
xfix1 += Blockly.Lua.injectId(Blockly.Lua.STATEMENT_PREFIX, block);
|
||||
}
|
||||
@@ -28,16 +28,16 @@ Blockly.Lua['procedures_defreturn'] = function(block) {
|
||||
if (xfix1) {
|
||||
xfix1 = Blockly.Lua.prefixLines(xfix1, Blockly.Lua.INDENT);
|
||||
}
|
||||
var loopTrap = '';
|
||||
let loopTrap = '';
|
||||
if (Blockly.Lua.INFINITE_LOOP_TRAP) {
|
||||
loopTrap = Blockly.Lua.prefixLines(
|
||||
Blockly.Lua.injectId(Blockly.Lua.INFINITE_LOOP_TRAP, block),
|
||||
Blockly.Lua.INDENT);
|
||||
}
|
||||
var branch = Blockly.Lua.statementToCode(block, 'STACK');
|
||||
var returnValue = Blockly.Lua.valueToCode(block, 'RETURN',
|
||||
let branch = Blockly.Lua.statementToCode(block, 'STACK');
|
||||
let returnValue = Blockly.Lua.valueToCode(block, 'RETURN',
|
||||
Blockly.Lua.ORDER_NONE) || '';
|
||||
var xfix2 = '';
|
||||
let xfix2 = '';
|
||||
if (branch && returnValue) {
|
||||
// After executing the function body, revisit this block for the return.
|
||||
xfix2 = xfix1;
|
||||
@@ -47,13 +47,13 @@ Blockly.Lua['procedures_defreturn'] = function(block) {
|
||||
} else if (!branch) {
|
||||
branch = '';
|
||||
}
|
||||
var args = [];
|
||||
var variables = block.getVars();
|
||||
for (var i = 0; i < variables.length; i++) {
|
||||
const args = [];
|
||||
const variables = block.getVars();
|
||||
for (let i = 0; i < variables.length; i++) {
|
||||
args[i] = Blockly.Lua.nameDB_.getName(variables[i],
|
||||
Blockly.VARIABLE_CATEGORY_NAME);
|
||||
}
|
||||
var code = 'function ' + funcName + '(' + args.join(', ') + ')\n' +
|
||||
let code = 'function ' + funcName + '(' + args.join(', ') + ')\n' +
|
||||
xfix1 + loopTrap + branch + xfix2 + returnValue + 'end\n';
|
||||
code = Blockly.Lua.scrub_(block, code);
|
||||
// Add % so as not to collide with helper functions in definitions list.
|
||||
@@ -68,15 +68,15 @@ Blockly.Lua['procedures_defnoreturn'] =
|
||||
|
||||
Blockly.Lua['procedures_callreturn'] = function(block) {
|
||||
// Call a procedure with a return value.
|
||||
var funcName = Blockly.Lua.nameDB_.getName(
|
||||
const funcName = Blockly.Lua.nameDB_.getName(
|
||||
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
|
||||
var args = [];
|
||||
var variables = block.getVars();
|
||||
for (var i = 0; i < variables.length; i++) {
|
||||
const args = [];
|
||||
const variables = block.getVars();
|
||||
for (let i = 0; i < variables.length; i++) {
|
||||
args[i] = Blockly.Lua.valueToCode(block, 'ARG' + i,
|
||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
||||
}
|
||||
var code = funcName + '(' + args.join(', ') + ')';
|
||||
const code = funcName + '(' + args.join(', ') + ')';
|
||||
return [code, Blockly.Lua.ORDER_HIGH];
|
||||
};
|
||||
|
||||
@@ -84,15 +84,15 @@ Blockly.Lua['procedures_callnoreturn'] = function(block) {
|
||||
// Call a procedure with no return value.
|
||||
// Generated code is for a function call as a statement is the same as a
|
||||
// function call as a value, with the addition of line ending.
|
||||
var tuple = Blockly.Lua['procedures_callreturn'](block);
|
||||
const tuple = Blockly.Lua['procedures_callreturn'](block);
|
||||
return tuple[0] + '\n';
|
||||
};
|
||||
|
||||
Blockly.Lua['procedures_ifreturn'] = function(block) {
|
||||
// Conditionally return value from a procedure.
|
||||
var condition = Blockly.Lua.valueToCode(block, 'CONDITION',
|
||||
const condition = Blockly.Lua.valueToCode(block, 'CONDITION',
|
||||
Blockly.Lua.ORDER_NONE) || 'false';
|
||||
var code = 'if ' + condition + ' then\n';
|
||||
let code = 'if ' + condition + ' then\n';
|
||||
if (Blockly.Lua.STATEMENT_SUFFIX) {
|
||||
// Inject any statement suffix here since the regular one at the end
|
||||
// will not get executed if the return is triggered.
|
||||
@@ -101,7 +101,7 @@ Blockly.Lua['procedures_ifreturn'] = function(block) {
|
||||
Blockly.Lua.INDENT);
|
||||
}
|
||||
if (block.hasReturnValue_) {
|
||||
var value = Blockly.Lua.valueToCode(block, 'VALUE',
|
||||
const value = Blockly.Lua.valueToCode(block, 'VALUE',
|
||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
||||
code += Blockly.Lua.INDENT + 'return ' + value + '\n';
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user