Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions generators/dart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
goog.provide('Blockly.Dart');

goog.require('Blockly.Generator');
goog.require('Blockly.Names');
goog.require('Blockly.Variables');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.string');

goog.requireType('Blockly.Block');
goog.requireType('Blockly.Workspace');

/**
* Dart code generator.
Expand Down Expand Up @@ -268,7 +271,7 @@ Blockly.Dart.getAdjusted = function(block, atId, opt_delta, opt_negate,
/** @type {string|number} */
let at = this.valueToCode(block, atId, outerOrder) || defaultAtIndex;

if (Blockly.isNumber(at)) {
if (Blockly.utils.string.isNumber(at)) {
// If the index is a naked number, adjust it right now.
at = parseInt(at, 10) + delta;
if (opt_negate) {
Expand Down
13 changes: 7 additions & 6 deletions generators/dart/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
goog.provide('Blockly.Dart.loops');

goog.require('Blockly.Dart');
goog.require('Blockly.utils.string');


Blockly.Dart['controls_repeat_ext'] = function(block) {
Expand All @@ -32,7 +33,7 @@ Blockly.Dart['controls_repeat_ext'] = function(block) {
const loopVar = Blockly.Dart.nameDB_.getDistinctName(
'count', Blockly.VARIABLE_CATEGORY_NAME);
let endVar = repeats;
if (!repeats.match(/^\w+$/) && !Blockly.isNumber(repeats)) {
if (!repeats.match(/^\w+$/) && !Blockly.utils.string.isNumber(repeats)) {
endVar = Blockly.Dart.nameDB_.getDistinctName(
'repeat_end', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + endVar + ' = ' + repeats + ';\n';
Expand Down Expand Up @@ -73,8 +74,8 @@ Blockly.Dart['controls_for'] = function(block) {
let branch = Blockly.Dart.statementToCode(block, 'DO');
branch = Blockly.Dart.addLoopTrap(branch, block);
let code;
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 arguments are simple numbers.
const up = Number(argument0) <= Number(argument1);
code = 'for (' + variable0 + ' = ' + argument0 + '; ' +
Expand All @@ -91,13 +92,13 @@ Blockly.Dart['controls_for'] = function(block) {
code = '';
// Cache non-trivial values to variables to prevent repeated look-ups.
let startVar = argument0;
if (!argument0.match(/^\w+$/) && !Blockly.isNumber(argument0)) {
if (!argument0.match(/^\w+$/) && !Blockly.utils.string.isNumber(argument0)) {
startVar = Blockly.Dart.nameDB_.getDistinctName(
variable0 + '_start', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + startVar + ' = ' + argument0 + ';\n';
}
let endVar = argument1;
if (!argument1.match(/^\w+$/) && !Blockly.isNumber(argument1)) {
if (!argument1.match(/^\w+$/) && !Blockly.utils.string.isNumber(argument1)) {
endVar = Blockly.Dart.nameDB_.getDistinctName(
variable0 + '_end', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + endVar + ' = ' + argument1 + ';\n';
Expand All @@ -107,7 +108,7 @@ Blockly.Dart['controls_for'] = function(block) {
const incVar = Blockly.Dart.nameDB_.getDistinctName(
variable0 + '_inc', Blockly.VARIABLE_CATEGORY_NAME);
code += 'num ' + incVar + ' = ';
if (Blockly.isNumber(increment)) {
if (Blockly.utils.string.isNumber(increment)) {
code += Math.abs(increment) + ';\n';
} else {
code += '(' + increment + ').abs();\n';
Expand Down
2 changes: 1 addition & 1 deletion generators/dart/variables_dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* @fileoverview Generating Dart for dynamic variable blocks.
* @suppress {extraRequire|missingRequire}
* @suppress {extraRequire}
*/
'use strict';

Expand Down
6 changes: 5 additions & 1 deletion generators/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
goog.provide('Blockly.JavaScript');

goog.require('Blockly.Generator');
goog.require('Blockly.Variables');
goog.require('Blockly.Names');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.global');
goog.require('Blockly.utils.object');
goog.require('Blockly.utils.string');
goog.requireType('Blockly.Block');
goog.requireType('Blockly.Workspace');


/**
Expand Down Expand Up @@ -289,7 +293,7 @@ Blockly.JavaScript.getAdjusted = function(block, atId, opt_delta, opt_negate,

let at = this.valueToCode(block, atId, outerOrder) || defaultAtIndex;

if (Blockly.isNumber(at)) {
if (Blockly.utils.string.isNumber(at)) {
// If the index is a naked number, adjust it right now.
at = Number(at) + delta;
if (opt_negate) {
Expand Down
13 changes: 7 additions & 6 deletions generators/javascript/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ goog.provide('Blockly.JavaScript.loops');

goog.require('Blockly.JavaScript');
goog.require('Blockly.loopMixin');
goog.require('Blockly.utils.string');


Blockly.JavaScript['controls_repeat_ext'] = function(block) {
Expand All @@ -33,7 +34,7 @@ Blockly.JavaScript['controls_repeat_ext'] = function(block) {
const loopVar = Blockly.JavaScript.nameDB_.getDistinctName(
'count', Blockly.VARIABLE_CATEGORY_NAME);
let endVar = repeats;
if (!repeats.match(/^\w+$/) && !Blockly.isNumber(repeats)) {
if (!repeats.match(/^\w+$/) && !Blockly.utils.string.isNumber(repeats)) {
endVar = Blockly.JavaScript.nameDB_.getDistinctName(
'repeat_end', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + endVar + ' = ' + repeats + ';\n';
Expand Down Expand Up @@ -75,8 +76,8 @@ Blockly.JavaScript['controls_for'] = function(block) {
let branch = Blockly.JavaScript.statementToCode(block, 'DO');
branch = Blockly.JavaScript.addLoopTrap(branch, block);
let code;
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 arguments are simple numbers.
const up = Number(argument0) <= Number(argument1);
code = 'for (' + variable0 + ' = ' + argument0 + '; ' +
Expand All @@ -93,13 +94,13 @@ Blockly.JavaScript['controls_for'] = function(block) {
code = '';
// Cache non-trivial values to variables to prevent repeated look-ups.
let startVar = argument0;
if (!argument0.match(/^\w+$/) && !Blockly.isNumber(argument0)) {
if (!argument0.match(/^\w+$/) && !Blockly.utils.string.isNumber(argument0)) {
startVar = Blockly.JavaScript.nameDB_.getDistinctName(
variable0 + '_start', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + startVar + ' = ' + argument0 + ';\n';
}
let endVar = argument1;
if (!argument1.match(/^\w+$/) && !Blockly.isNumber(argument1)) {
if (!argument1.match(/^\w+$/) && !Blockly.utils.string.isNumber(argument1)) {
endVar = Blockly.JavaScript.nameDB_.getDistinctName(
variable0 + '_end', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + endVar + ' = ' + argument1 + ';\n';
Expand All @@ -109,7 +110,7 @@ Blockly.JavaScript['controls_for'] = function(block) {
const incVar = Blockly.JavaScript.nameDB_.getDistinctName(
variable0 + '_inc', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + incVar + ' = ';
if (Blockly.isNumber(increment)) {
if (Blockly.utils.string.isNumber(increment)) {
code += Math.abs(increment) + ';\n';
} else {
code += 'Math.abs(' + increment + ');\n';
Expand Down
5 changes: 4 additions & 1 deletion generators/lua.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
/**
* @fileoverview Helper functions for generating Lua for blocks.
* Based on Ellen Spertus's blocky-lua project.
* @suppress {missingRequire|checkTypes|globalThis}
* @suppress {checkTypes|globalThis}
*/
'use strict';

goog.provide('Blockly.Lua');

goog.require('Blockly.Generator');
goog.require('Blockly.Names');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.object');
goog.require('Blockly.utils.string');
goog.requireType('Blockly.Block');
goog.requireType('Blockly.Workspace');


/**
Expand Down
9 changes: 5 additions & 4 deletions generators/lua/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
goog.provide('Blockly.Lua.loops');

goog.require('Blockly.Lua');
goog.require('Blockly.utils.string');


/**
Expand Down Expand Up @@ -53,7 +54,7 @@ Blockly.Lua['controls_repeat_ext'] = function(block) {
repeats = Blockly.Lua.valueToCode(block, 'TIMES',
Blockly.Lua.ORDER_NONE) || '0';
}
if (Blockly.isNumber(repeats)) {
if (Blockly.utils.string.isNumber(repeats)) {
repeats = parseInt(repeats, 10);
} else {
repeats = 'math.floor(' + repeats + ')';
Expand Down Expand Up @@ -100,8 +101,8 @@ Blockly.Lua['controls_for'] = function(block) {
branch = Blockly.Lua.addContinueLabel_(branch);
let code = '';
let incValue;
if (Blockly.isNumber(startVar) && Blockly.isNumber(endVar) &&
Blockly.isNumber(increment)) {
if (Blockly.utils.string.isNumber(startVar) && Blockly.utils.string.isNumber(endVar) &&
Blockly.utils.string.isNumber(increment)) {
// All arguments are simple numbers.
const up = Number(startVar) <= Number(endVar);
const step = Math.abs(Number(increment));
Expand All @@ -113,7 +114,7 @@ Blockly.Lua['controls_for'] = function(block) {
incValue = Blockly.Lua.nameDB_.getDistinctName(
variable0 + '_inc', Blockly.VARIABLE_CATEGORY_NAME);
code += incValue + ' = ';
if (Blockly.isNumber(increment)) {
if (Blockly.utils.string.isNumber(increment)) {
code += Math.abs(increment) + '\n';
} else {
code += 'math.abs(' + increment + ')\n';
Expand Down
7 changes: 5 additions & 2 deletions generators/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@

/**
* @fileoverview Helper functions for generating PHP for blocks.
* @suppress {missingRequire|checkTypes|globalThis}
* @suppress {checkTypes|globalThis}
*/
'use strict';

goog.provide('Blockly.PHP');

goog.require('Blockly.Generator');
goog.require('Blockly.Names');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.object');
goog.require('Blockly.utils.string');
goog.requireType('Blockly.Block');
goog.requireType('Blockly.Workspace');


/**
Expand Down Expand Up @@ -271,7 +274,7 @@ Blockly.PHP.getAdjusted = function(block, atId, opt_delta, opt_negate,
}
let at = this.valueToCode(block, atId, outerOrder) || defaultAtIndex;

if (Blockly.isNumber(at)) {
if (Blockly.utils.string.isNumber(at)) {
// If the index is a naked number, adjust it right now.
at = Number(at) + delta;
if (opt_negate) {
Expand Down
7 changes: 4 additions & 3 deletions generators/php/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
goog.provide('Blockly.PHP.lists');

goog.require('Blockly.PHP');
goog.require('Blockly.utils.string');


Blockly.PHP['lists_create_empty'] = function(block) {
Expand Down Expand Up @@ -387,7 +388,7 @@ Blockly.PHP['lists_getSublist'] = function(block) {
at2 = Blockly.PHP.getAdjusted(block, 'AT2', 0, false,
Blockly.PHP.ORDER_SUBTRACTION);
length = at2 + ' - ';
if (Blockly.isNumber(String(at1)) || String(at1).match(/^\(.+\)$/)) {
if (Blockly.utils.string.isNumber(String(at1)) || String(at1).match(/^\(.+\)$/)) {
length += at1;
} else {
length += '(' + at1 + ')';
Expand All @@ -398,15 +399,15 @@ Blockly.PHP['lists_getSublist'] = function(block) {
at2 = Blockly.PHP.getAdjusted(block, 'AT2', 0, false,
Blockly.PHP.ORDER_SUBTRACTION);
length = 'count(' + list + ') - ' + at2 + ' - ';
if (Blockly.isNumber(String(at1)) || String(at1).match(/^\(.+\)$/)) {
if (Blockly.utils.string.isNumber(String(at1)) || String(at1).match(/^\(.+\)$/)) {
length += at1;
} else {
length += '(' + at1 + ')';
}
break;
case 'LAST':
length = 'count(' + list + ') - ';
if (Blockly.isNumber(String(at1)) || String(at1).match(/^\(.+\)$/)) {
if (Blockly.utils.string.isNumber(String(at1)) || String(at1).match(/^\(.+\)$/)) {
length += at1;
} else {
length += '(' + at1 + ')';
Expand Down
13 changes: 7 additions & 6 deletions generators/php/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
goog.provide('Blockly.PHP.loops');

goog.require('Blockly.PHP');
goog.require('Blockly.utils.string');


Blockly.PHP['controls_repeat_ext'] = function(block) {
Expand All @@ -32,7 +33,7 @@ Blockly.PHP['controls_repeat_ext'] = function(block) {
const loopVar = Blockly.PHP.nameDB_.getDistinctName(
'count', Blockly.VARIABLE_CATEGORY_NAME);
let endVar = repeats;
if (!repeats.match(/^\w+$/) && !Blockly.isNumber(repeats)) {
if (!repeats.match(/^\w+$/) && !Blockly.utils.string.isNumber(repeats)) {
endVar = Blockly.PHP.nameDB_.getDistinctName(
'repeat_end', Blockly.VARIABLE_CATEGORY_NAME);
code += endVar + ' = ' + repeats + ';\n';
Expand Down Expand Up @@ -73,8 +74,8 @@ Blockly.PHP['controls_for'] = function(block) {
let branch = Blockly.PHP.statementToCode(block, 'DO');
branch = Blockly.PHP.addLoopTrap(branch, block);
let code;
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 arguments are simple numbers.
const up = Number(argument0) <= Number(argument1);
code = 'for (' + variable0 + ' = ' + argument0 + '; ' +
Expand All @@ -91,13 +92,13 @@ Blockly.PHP['controls_for'] = function(block) {
code = '';
// Cache non-trivial values to variables to prevent repeated look-ups.
let startVar = argument0;
if (!argument0.match(/^\w+$/) && !Blockly.isNumber(argument0)) {
if (!argument0.match(/^\w+$/) && !Blockly.utils.string.isNumber(argument0)) {
startVar = Blockly.PHP.nameDB_.getDistinctName(
variable0 + '_start', Blockly.VARIABLE_CATEGORY_NAME);
code += startVar + ' = ' + argument0 + ';\n';
}
let endVar = argument1;
if (!argument1.match(/^\w+$/) && !Blockly.isNumber(argument1)) {
if (!argument1.match(/^\w+$/) && !Blockly.utils.string.isNumber(argument1)) {
endVar = Blockly.PHP.nameDB_.getDistinctName(
variable0 + '_end', Blockly.VARIABLE_CATEGORY_NAME);
code += endVar + ' = ' + argument1 + ';\n';
Expand All @@ -107,7 +108,7 @@ Blockly.PHP['controls_for'] = function(block) {
const incVar = Blockly.PHP.nameDB_.getDistinctName(
variable0 + '_inc', Blockly.VARIABLE_CATEGORY_NAME);
code += incVar + ' = ';
if (Blockly.isNumber(increment)) {
if (Blockly.utils.string.isNumber(increment)) {
code += Math.abs(increment) + ';\n';
} else {
code += 'abs(' + increment + ');\n';
Expand Down
2 changes: 2 additions & 0 deletions generators/php/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
goog.provide('Blockly.PHP.procedures');

goog.require('Blockly.PHP');
goog.require('Blockly.Names');
goog.require('Blockly.Variables');


Blockly.PHP['procedures_defreturn'] = function(block) {
Expand Down
6 changes: 5 additions & 1 deletion generators/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
goog.provide('Blockly.Python');

goog.require('Blockly.Generator');
goog.require('Blockly.Names');
goog.require('Blockly.Variables');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.string');
goog.requireType('Blockly.Block');
goog.requireType('Blockly.Workspace');


/**
Expand Down Expand Up @@ -305,7 +309,7 @@ Blockly.Python.getAdjustedInt = function(block, atId, opt_delta, opt_negate) {
const atOrder = delta ? this.ORDER_ADDITIVE : this.ORDER_NONE;
let at = this.valueToCode(block, atId, atOrder) || defaultAtIndex;

if (Blockly.isNumber(at)) {
if (Blockly.utils.string.isNumber(at)) {
// If the index is a naked number, adjust it right now.
at = parseInt(at, 10) + delta;
if (opt_negate) {
Expand Down
3 changes: 2 additions & 1 deletion generators/python/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading