kopia lustrzana https://github.com/backface/turtlestitch
check for conflicting names in formal params and already existing vars
rodzic
0d65bc9b79
commit
f60ddf7c4c
69
blocks.js
69
blocks.js
|
@ -686,6 +686,7 @@ SyntaxElementMorph.prototype.refactorVarInStack = function (oldName, newName, is
|
||||||
|
|
||||||
if (this instanceof CustomCommandBlockMorph
|
if (this instanceof CustomCommandBlockMorph
|
||||||
&& this.definition.body
|
&& this.definition.body
|
||||||
|
&& isNil(this.definition.declarations[oldName])
|
||||||
&& !contains(this.definition.variableNames, oldName)) {
|
&& !contains(this.definition.variableNames, oldName)) {
|
||||||
this.definition.body.expression.refactorVarInStack(oldName, newName);
|
this.definition.body.expression.refactorVarInStack(oldName, newName);
|
||||||
}
|
}
|
||||||
|
@ -3077,28 +3078,58 @@ BlockMorph.prototype.refactorThisVar = function () {
|
||||||
new DialogBoxMorph(
|
new DialogBoxMorph(
|
||||||
this,
|
this,
|
||||||
function (newName) {
|
function (newName) {
|
||||||
|
var definer;
|
||||||
|
|
||||||
if (this.parent instanceof SyntaxElementMorph) {
|
if (this.parent instanceof SyntaxElementMorph) {
|
||||||
// script var
|
// script var
|
||||||
this.parentThatIsA(CommandBlockMorph).refactorVarInStack(oldName, newName, true);
|
definer = this.parentThatIsA(CommandBlockMorph);
|
||||||
|
if (definer.definesScriptVariable(newName)) {
|
||||||
|
varExistsError();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
definer.refactorVarInStack(oldName, newName, true);
|
||||||
|
}
|
||||||
} else if (receiver.hasSpriteVariable(oldName)) {
|
} else if (receiver.hasSpriteVariable(oldName)) {
|
||||||
// sprite local var
|
// sprite local var
|
||||||
receiver.refactorVariableInstances(oldName, newName, false);
|
if (receiver.hasSpriteVariable(newName)) {
|
||||||
receiver.customBlocks.forEach(function (eachBlock) {
|
varExistsError();
|
||||||
eachBlock.definition.body.expression.refactorVarInStack(oldName, newName);
|
return;
|
||||||
});
|
} else if (!isNil(ide.globalVariables.vars[newName])) {
|
||||||
|
varExistsError('as a global variable');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
receiver.refactorVariableInstances(oldName, newName, false);
|
||||||
|
receiver.customBlocks.forEach(function (eachBlock) {
|
||||||
|
eachBlock.definition.body.expression.refactorVarInStack(oldName, newName);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// global var
|
// global var
|
||||||
oldValue = ide.globalVariables.vars[oldName];
|
if (!isNil(ide.globalVariables.vars[newName])) {
|
||||||
stage.deleteVariable(oldName);
|
varExistsError();
|
||||||
stage.addVariable(newName, true);
|
return;
|
||||||
ide.globalVariables.vars[newName] = oldValue;
|
} else if (
|
||||||
|
detect(
|
||||||
|
stage.children,
|
||||||
|
function (any) {
|
||||||
|
return any.hasSpriteVariable(newName);
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
varExistsError('as a sprite local variable');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
oldValue = ide.globalVariables.vars[oldName];
|
||||||
|
stage.deleteVariable(oldName);
|
||||||
|
stage.addVariable(newName, true);
|
||||||
|
ide.globalVariables.vars[newName] = oldValue;
|
||||||
|
|
||||||
stage.refactorVariableInstances(oldName, newName, true);
|
stage.refactorVariableInstances(oldName, newName, true);
|
||||||
stage.forAllChildren(function (child) {
|
stage.forAllChildren(function (child) {
|
||||||
if (child instanceof SpriteMorph) {
|
if (child instanceof SpriteMorph) {
|
||||||
child.refactorVariableInstances(oldName, newName, true);
|
child.refactorVariableInstances(oldName, newName, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldWatcher && oldWatcher.isVisible) {
|
if (oldWatcher && oldWatcher.isVisible) {
|
||||||
|
@ -3117,6 +3148,14 @@ BlockMorph.prototype.refactorThisVar = function () {
|
||||||
this.fullImage(), // pic
|
this.fullImage(), // pic
|
||||||
InputSlotMorph.prototype.getVarNamesDict.call(this)
|
InputSlotMorph.prototype.getVarNamesDict.call(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function varExistsError (where) {
|
||||||
|
ide.inform(
|
||||||
|
'Variable exists',
|
||||||
|
'A variable with this name already exists ' +
|
||||||
|
(where || 'in this context') + '.'
|
||||||
|
);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// BlockMorph drawing
|
// BlockMorph drawing
|
||||||
|
|
Ładowanie…
Reference in New Issue