mirror of
https://github.com/google/blockly.git
synced 2026-02-13 11:00:10 +01:00
fix: Fix bug that prevented deleting a variable referenced by two connected blocks (#9563)
* fix: Fix bug that prevented deleting a variable referenced by two connected blocks * fix: Remove inadvertent .only
This commit is contained in:
@@ -291,7 +291,10 @@ export class Connection {
|
||||
}
|
||||
|
||||
let event;
|
||||
if (eventUtils.isEnabled()) {
|
||||
if (
|
||||
eventUtils.isEnabled() &&
|
||||
!childConnection.getSourceBlock().isDeadOrDying()
|
||||
) {
|
||||
event = new (eventUtils.get(EventType.BLOCK_MOVE))(
|
||||
childConnection.getSourceBlock(),
|
||||
) as BlockMove;
|
||||
|
||||
@@ -315,6 +315,8 @@ export class VariableMap
|
||||
}
|
||||
try {
|
||||
for (let i = 0; i < uses.length; i++) {
|
||||
if (uses[i].isDeadOrDying()) continue;
|
||||
|
||||
uses[i].dispose(true);
|
||||
}
|
||||
const variables = this.variableMap.get(variable.getType());
|
||||
|
||||
@@ -30,6 +30,25 @@ suite('Variables', function () {
|
||||
'variableTypes': ['', 'type1', 'type2'],
|
||||
},
|
||||
],
|
||||
'output': null,
|
||||
},
|
||||
// Block for variable setter.
|
||||
{
|
||||
'type': 'set_var_block',
|
||||
'message0': '%{BKY_VARIABLES_SET}',
|
||||
'args0': [
|
||||
{
|
||||
'type': 'field_variable',
|
||||
'name': 'VAR',
|
||||
'variableTypes': ['', 'type1', 'type2'],
|
||||
},
|
||||
{
|
||||
'type': 'input_value',
|
||||
'name': 'VALUE',
|
||||
},
|
||||
],
|
||||
'previousStatement': null,
|
||||
'nextStatement': null,
|
||||
},
|
||||
]);
|
||||
this.variableMap = this.workspace.getVariableMap();
|
||||
@@ -59,6 +78,21 @@ suite('Variables', function () {
|
||||
return block;
|
||||
}
|
||||
|
||||
test('can be deleted when two connected blocks reference the same variable', function () {
|
||||
const getter = new Blockly.Block(this.workspace, 'get_var_block');
|
||||
getter.getField('VAR').setValue('1');
|
||||
|
||||
const setter = new Blockly.Block(this.workspace, 'set_var_block');
|
||||
setter.getField('VAR').setValue('1');
|
||||
setter.getInput('VALUE').connection.connect(getter.outputConnection);
|
||||
|
||||
this.variableMap.deleteVariable(this.variableMap.getVariableById('1'));
|
||||
// Both blocks should have been deleted.
|
||||
assert.equal(0, this.workspace.getAllBlocks(false).length);
|
||||
// The variable itself should have been deleted.
|
||||
assert.equal(this.variableMap.getVariableById('1'), undefined);
|
||||
});
|
||||
|
||||
suite('allUsedVarModels', function () {
|
||||
test('All used', function () {
|
||||
createTestVarBlock(this.workspace, '1');
|
||||
|
||||
Reference in New Issue
Block a user