Skip to content

Commit

Permalink
Fix error conditions for setParent google#4989
Browse files Browse the repository at this point in the history
* Error now thrown when calling `a.setParent(b)` on non-null b if the output/previous connection of a is not connected to an input/next connection of b without removing block from old parent's child list.
* Error now thrown when calling `a.setParent(null)` if a is connected to a superior block.
* Adjusted comment to reflect that blocks were no longer being disconnected in this method.
* Also changed == to === per google#4924 (`newParent` and `this.parentBlock_` must both be instances of `Blockly.Block`).
  • Loading branch information
jschanker committed Jul 8, 2021
1 parent 0d88de3 commit f5d9606
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,9 @@ Blockly.Block.prototype.setParent = function(newParent) {
throw Error('Block connected to superior one that is not new parent.');
} else if (!isConnected && newParent) {
throw Error('Block not connected to new parent.');
} else if (connection && !newParent) {
// TODO #4989: Clean up code so that error can be thrown in this case
// without breaking things.
// throw Error('Cannot set parent to null while block is still connected
// to superior block.');
} else if (isConnected && !newParent) {
throw Error('Cannot set parent to null while block is still connected to'
+ ' superior block.');
}

if (this.parentBlock_) {
Expand Down

0 comments on commit f5d9606

Please sign in to comment.