Don't modify workspace.variableList in generators

Fixes #677.
This commit is contained in:
Rodrigo Queiro
2016-10-06 16:38:06 +02:00
parent de9337edde
commit 90082ef495
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' : '';