Merge pull request #679 from drigz/bugfix/677

Don't modify workspace.variableList in generators
This commit is contained in:
RoboErikG
2016-10-11 12:31:13 -07:00
committed by GitHub
2 changed files with 14 additions and 22 deletions

View File

@@ -30,18 +30,14 @@ goog.require('Blockly.PHP');
Blockly.PHP['procedures_defreturn'] = function(block) {
// Define a procedure with a return value.
// First, add a 'global' statement for every variable that is assigned.
var globals = block.workspace.variableList;
for (var i = globals.length - 1; i >= 0; i--) {
var varName = globals[i];
if (block.arguments_.indexOf(varName) == -1) {
globals[i] = Blockly.PHP.variableDB_.getName(varName,
Blockly.Variables.NAME_TYPE);
} else {
// This variable is actually a parameter name. Do not include it in
// the list of globals, thus allowing it be of local scope.
globals.splice(i, 1);
}
// First, add a 'global' statement for every variable that is not shadowed by
// a local parameter.
var globals = [];
for (var i = 0, varName; varName = block.workspace.variableList[i]; i++) {
if (block.arguments_.indexOf(varName) == -1) {
globals.push(Blockly.PHP.variableDB_.getName(varName,
Blockly.Variables.NAME_TYPE));
}
}
globals = globals.length ? ' global ' + globals.join(', ') + ';\n' : '';

View File

@@ -31,17 +31,13 @@ goog.require('Blockly.Python');
Blockly.Python['procedures_defreturn'] = function(block) {
// Define a procedure with a return value.
// First, add a 'global' statement for every variable that is assigned.
var globals = block.workspace.variableList;
for (var i = globals.length - 1; i >= 0; i--) {
var varName = globals[i];
// First, add a 'global' statement for every variable that is not shadowed by
// a local parameter.
var globals = [];
for (var i = 0, varName; varName = block.workspace.variableList[i]; i++) {
if (block.arguments_.indexOf(varName) == -1) {
globals[i] = Blockly.Python.variableDB_.getName(varName,
Blockly.Variables.NAME_TYPE);
} else {
// This variable is actually a parameter name. Do not include it in
// the list of globals, thus allowing it be of local scope.
globals.splice(i, 1);
globals.push(Blockly.Python.variableDB_.getName(varName,
Blockly.Variables.NAME_TYPE));
}
}
globals = globals.length ? ' global ' + globals.join(', ') + '\n' : '';