chore: fix missing requires in generators (#5744)

* chore: fix some missing requires in generators

* chore: fix missing requires in dart block generators

* chore: replace Blockly.isNumber with Blockly.utils.string.isNumber in generators

* chore: fix more missing requires in block generators
This commit is contained in:
Rachel Fenichel
2021-11-30 08:51:21 -08:00
committed by GitHub
parent 1a992386ae
commit 4db047ff32
18 changed files with 238 additions and 210 deletions

View File

@@ -13,6 +13,7 @@
goog.provide('Blockly.Python.lists');
goog.require('Blockly.Python');
goog.require('Blockly.utils.string');
Blockly.Python['lists_create_empty'] = function(block) {
@@ -282,7 +283,7 @@ Blockly.Python['lists_getSublist'] = function(block) {
at2 = Blockly.Python.getAdjustedInt(block, 'AT2', 0, true);
// Ensure that if the result calculated is 0 that sub-sequence will
// include all elements as expected.
if (!Blockly.isNumber(String(at2))) {
if (!Blockly.utils.string.isNumber(String(at2))) {
Blockly.Python.definitions_['import_sys'] = 'import sys';
at2 += ' or sys.maxsize';
} else if (at2 === 0) {

View File

@@ -13,6 +13,7 @@
goog.provide('Blockly.Python.loops');
goog.require('Blockly.Python');
goog.require('Blockly.utils.string');
Blockly.Python['controls_repeat_ext'] = function(block) {
@@ -26,7 +27,7 @@ Blockly.Python['controls_repeat_ext'] = function(block) {
repeats = Blockly.Python.valueToCode(block, 'TIMES',
Blockly.Python.ORDER_NONE) || '0';
}
if (Blockly.isNumber(repeats)) {
if (Blockly.utils.string.isNumber(repeats)) {
repeats = parseInt(repeats, 10);
} else {
repeats = 'int(' + repeats + ')';
@@ -97,8 +98,8 @@ Blockly.Python['controls_for'] = function(block) {
defineDownRange() + '(' + start + ', ' + end + ', ' + inc + ')';
};
if (Blockly.isNumber(argument0) && Blockly.isNumber(argument1) &&
Blockly.isNumber(increment)) {
if (Blockly.utils.string.isNumber(argument0) && Blockly.utils.string.isNumber(argument1) &&
Blockly.utils.string.isNumber(increment)) {
// All parameters are simple numbers.
argument0 = Number(argument0);
argument1 = Number(argument1);
@@ -136,7 +137,7 @@ Blockly.Python['controls_for'] = function(block) {
} else {
// Cache non-trivial values to variables to prevent repeated look-ups.
const scrub = function(arg, suffix) {
if (Blockly.isNumber(arg)) {
if (Blockly.utils.string.isNumber(arg)) {
// Simple number.
arg = Number(arg);
} else if (arg.match(/^\w+$/)) {

View File

@@ -13,6 +13,7 @@
goog.provide('Blockly.Python.procedures');
goog.require('Blockly.Python');
goog.require('Blockly.Variables');
Blockly.Python['procedures_defreturn'] = function(block) {

View File

@@ -13,6 +13,7 @@
goog.provide('Blockly.Python.texts');
goog.require('Blockly.Python');
goog.require('Blockly.utils.string');
Blockly.Python['text'] = function(block) {
@@ -200,7 +201,7 @@ Blockly.Python['text_getSubstring'] = function(block) {
at2 = Blockly.Python.getAdjustedInt(block, 'AT2', 0, true);
// Ensure that if the result calculated is 0 that sub-sequence will
// include all elements as expected.
if (!Blockly.isNumber(String(at2))) {
if (!Blockly.utils.string.isNumber(String(at2))) {
Blockly.Python.definitions_['import_sys'] = 'import sys';
at2 += ' or sys.maxsize';
} else if (at2 === 0) {