Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: non-nullable check for block variable and removed ! in layout_ #7536

Merged
merged 10 commits into from
Sep 25, 2023
17 changes: 10 additions & 7 deletions core/flyout_vertical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,32 @@ export class VerticalFlyout extends Flyout {
for (let i = 0, item; (item = contents[i]); i++) {
if (item.type === 'block') {
const block = item.block;
const allBlocks = block!.getDescendants(false);
if (block == undefined || block == null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please squash your commits

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is redundant, block == null checks both null and undefined. We would both checks with strict equality i.e. block === undefined || block === null

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case if (block) will do fine, because we aren't trying to distinguish between the two cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I just add if (block) than it shows "'block' is possibly 'undefined'." error. So, I added condition if (block == null) as suggested by rachna.

continue;
}
const allBlocks = block.getDescendants(false);
for (let j = 0, child; (child = allBlocks[j]); j++) {
// Mark blocks as being inside a flyout. This is used to detect and
// prevent the closure of the flyout if the user right-clicks on such
// a block.
child.isInFlyout = true;
}
const root = block!.getSvgRoot();
const blockHW = block!.getHeightWidth();
const moveX = block!.outputConnection
const root = block.getSvgRoot();
const blockHW = block.getHeightWidth();
const moveX = block.outputConnection
? cursorX - this.tabWidth_
: cursorX;
block!.moveBy(moveX, cursorY);
block.moveBy(moveX, cursorY);

const rect = this.createRect_(
block!,
block,
this.RTL ? moveX - blockHW.width : moveX,
cursorY,
blockHW,
i,
);

this.addBlockListeners_(root, block!, rect);
this.addBlockListeners_(root, block, rect);

cursorY += blockHW.height + gaps[i];
} else if (item.type === 'button') {
Expand Down