Skip to content

Commit

Permalink
fix: add more overridden casted methods to BlockSvg
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Feb 25, 2022
1 parent 3f44f82 commit 7cc375b
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
74 changes: 72 additions & 2 deletions core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,77 @@ class BlockSvg extends Block {
* @override
*/
getParent() {
return /** @type {!BlockSvg} */ (super.getParent());
return /** @type {?BlockSvg} */ (super.getParent());
}

/**
* @override
* @return {?BlockSvg} The block (if any) that surrounds the current block.
*/
getSurroundParent() {
return /** @type {?BlockSvg} */ (super.getSurroundParent());
}

/**
* @override
* @return {?BlockSvg} The next statement block or null.
*/
getNextBlock() {
return /** @type {?BlockSvg} */ (super.getNextBlock());
}

/**
* @override
* @return {?BlockSvg} The previou statement block or null.
*/
getPreviousBlock() {
return /** @type {?BlockSvg} */ (super.getPreviousBlock());
}

/**
* @override
* @return {?RenderedConnection} The first statement connection or null.
* @package
*/
getFirstStatementConnection() {
return /** @type {?RenderedConnection} */ (
super.getFirstStatementConnection());
}

/**
* @override
* @return {!BlockSvg} The top block in a stack.
*/
getTopStackBlock() {
return /** @type {!BlockSvg} */ (super.getTopStackBlock());
}

/**
* @override
* @param {boolean} ordered Sort the list if true.
* @return {!Array<!BlockSvg>} Children of this block.
*/
getChildren(ordered) {
return /** @type {!Array<!BlockSvg>} */ (super.getChildren(ordered));
}

/**
* @override
* @param {boolean} ordered Sort the list if true.
* @return {!Array<!BlockSvg>} Descendants of this block.
*/
getDescendants(ordered) {
return /** @type {!Array<!BlockSvg>} */ (super.getDescendants(ordered));
}

/**
* @override
* @param {string} name The name of the input.
* @return {?BlockSvg} The attached value block, or null if the input is
* either disconnected or if the input does not exist.
*/
getInputTargetBlock(name) {
return /** @type {?BlockSvg} */ (super.getInputTargetBlock(name));
}

/**
Expand Down Expand Up @@ -1763,7 +1833,7 @@ class BlockSvg extends Block {
let height = this.height;
let width = this.width;
// Recursively add size of subsequent blocks.
const nextBlock = /** @type {!BlockSvg} */ (this.getNextBlock());
const nextBlock = this.getNextBlock();
if (nextBlock) {
const nextHeightWidth = nextBlock.getHeightWidth();
const workspace = /** @type {!WorkspaceSvg} */ (this.workspace);
Expand Down
3 changes: 1 addition & 2 deletions core/contextmenu_items.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ const addDeletableBlocks_ = function(block, deleteList) {
if (block.isDeletable()) {
Array.prototype.push.apply(deleteList, block.getDescendants(false));
} else {
const children = /* eslint-disable-next-line indent */
/** @type {!Array<!BlockSvg>} */ (block.getChildren(false));
const children = block.getChildren(false);
for (let i = 0; i < children.length; i++) {
addDeletableBlocks_(children[i], deleteList);
}
Expand Down
3 changes: 1 addition & 2 deletions core/mutator.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ class Mutator extends Icon {
}

this.rootBlock_ = this.block_.decompose(this.workspace_);
const blocks = /** @type {!Array<!BlockSvg>} */
(this.rootBlock_.getDescendants(false));
const blocks = this.rootBlock_.getDescendants(false);
for (let i = 0, child; (child = blocks[i]); i++) {
child.render();
}
Expand Down
3 changes: 1 addition & 2 deletions core/rendered_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ class RenderedConnection extends Connection {
stopTrackingAll() {
this.setTracking(false);
if (this.targetConnection) {
const blocks = /** @type {!Array<!BlockSvg>} */
(this.targetBlock().getDescendants(false));
const blocks = this.targetBlock().getDescendants(false);
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i];
// Stop tracking connections of all children.
Expand Down
3 changes: 1 addition & 2 deletions core/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,7 @@ const domToBlock = function(xmlBlock, workspace) {
// Generate list of all blocks.
if (workspace.rendered) {
const topBlockSvg = /** @type {!BlockSvg} */ (topBlock);
const blocks = /** @type {!Array<!BlockSvg>} */
(topBlock.getDescendants(false));
const blocks = topBlock.getDescendants(false);
topBlockSvg.setConnectionTracking(false);
// Render each block.
for (let i = blocks.length - 1; i >= 0; i--) {
Expand Down

0 comments on commit 7cc375b

Please sign in to comment.