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.
* Commented out error for when calling `a.setParent(null)` if a is connected to 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`).
* Fixed lint errors.
  • Loading branch information
jschanker committed Jul 8, 2021
1 parent f5d9606 commit b0f70a1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ Blockly.Block.prototype.setParent = function(newParent) {

// Check that block is connected to new parent if new parent is not null.
// After todo is addressed, throw error if block is not disconnected from
// superior block when setting newParent to null.
// superior block when setting newParent to null.
var connection = this.previousConnection || this.outputConnection;
var isConnected = !!(connection && connection.targetBlock());

Expand All @@ -756,8 +756,8 @@ Blockly.Block.prototype.setParent = function(newParent) {
} else if (!isConnected && newParent) {
throw Error('Block not connected to new parent.');
} else if (isConnected && !newParent) {
throw Error('Cannot set parent to null while block is still connected to'
+ ' superior block.');
throw Error('Cannot set parent to null while block is still connected to' +
' superior block.');
}

if (this.parentBlock_) {
Expand Down

0 comments on commit b0f70a1

Please sign in to comment.