-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome! It looks like this is your first pull request in Blockly, so here are a couple of tips:
-
You can find tips about contributing to Blockly and how to
validate your changes on our
developer site. -
All contributors must sign the Google Contributor License
Agreement (CLA). If the google-cla bot leaves a comment on this
PR, make sure you follow the instructions. -
We use conventional commits
to make versioning the package easier. Make sure your commit
message is in the proper format
or learn how to fix it. -
If any of the other checks on this PR fail, you can click on
them to learn why. It might be that your change caused a test
failure, or that you need to double-check the
style guide.
Thank you for opening this PR! A member of the Blockly team will review it soon.
Thanks for grabbing this issue! Next steps:
I'll keep an eye on this PR and approve workflow runs as needed. |
core/flyout_vertical.ts
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be just if (block) {
core/flyout_vertical.ts
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please squash your commits
core/flyout_vertical.ts
Outdated
@@ -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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Hi @rashmi29, I'm signing off for the weekend but I will take a look again on Monday. Thanks again for contributing, and have a great Grace Hopper if you're attending! |
nit: In the description section under
|
core/flyout_vertical.ts
Outdated
if (block == null) { | ||
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
if (block) {
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;
}
or we could just do
if (!block) 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;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you so much for the PR!
The basics
The details
Resolves
Fixes #7523
Proposed Changes
Reason for Changes
Non nullable check was not present in code. That might break the code when variable has no value assigned.
Test Coverage
I did npm run and tested all the buttons before and after and checked the entire functionality after my change.
Documentation
No documentation required
Additional Information