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

refactor(blocks): Migrate blocks/loops.js to TypeScript #6957

Merged
merged 3 commits into from
Apr 18, 2023

Conversation

rachel-fenichel
Copy link
Collaborator

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

Part of #6828

Proposed Changes

Migrates loop blocks, following the examples in #6900 and #6901

@rachel-fenichel rachel-fenichel requested a review from a team as a code owner April 7, 2023 00:02
@rachel-fenichel rachel-fenichel requested review from BeksOmega and cpcallen and removed request for BeksOmega April 7, 2023 00:02
@BeksOmega BeksOmega removed their assignment Apr 10, 2023
Copy link
Contributor

@cpcallen cpcallen left a comment

Choose a reason for hiding this comment

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

LGTM except for a few @Directives that should be removed. A few additional comments with queries for my curiosity.

blocks/loops.ts Outdated
*/

import * as goog from '../closure/goog/goog.js';
goog.declareModuleId('Blockly.libraryBlocks.loops');

/* eslint-disable-next-line no-unused-vars */
import type * as AbstractEvent from '../core/events/events_abstract.js';
import type {Abstract} from '../core/events/events_abstract.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

Two observations and an opinion:

  • Interesting that Closure Compiler did not object to the previous (broken) import—presumably because of the @suppress {checkTypes}.
  • Abstract is more popular in our codebase than AbstractEvent, but both appear.
  • I prefer AbstractEvent and think we should consider making it house style to always rename event imports to FooEvent for clarity.

(But not specifically requesting a change here.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

blocks/loops.ts Outdated
/**
* Mixin to add a context menu item to create a 'variables_get' block.
* Used by blocks 'controls_for' and 'controls_forEach'.
*
* @mixin
Copy link
Contributor

Choose a reason for hiding this comment

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

I have removed @mixin and @augments where I encountered them, as I had understood they were meaningless to our tooling (except Closure Compiler, but we aren't using it for type checking any more), and CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN in any case is local and doesn't get actual generated documentation. Am I mistaken?

For properties/methods, @package should be replaced @internal—but this is a non-exported top-level declaration, so it not applicable here and should be deleted.

As far as @readonly: this should also be deleted. I had a look at the TSreadonly keyword, but it also applies to (individual) properties, not top-level declarations. I think the closest thing to @readonly here would be to declare const MY_MIXIN = { /* ... */ } as const, but I don't really think it's terribly useful since it seems unlikely we'd inadvertently write code that tries to modify properties of the mixin.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Deleted mixin, augments, readonly, public and package annotations.

blocks/loops.ts Outdated
/**
* This mixin adds a check to make sure the 'controls_flow_statements' block
* is contained in a loop. Otherwise a warning is added to the block.
*
* @mixin
Copy link
Contributor

Choose a reason for hiding this comment

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

See above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

blocks/loops.ts Show resolved Hide resolved
blocks/loops.ts Outdated
@@ -243,9 +234,15 @@ Extensions.register(
'controls_flow_tooltip',
Extensions.buildTooltipForDropdown('FLOW', BREAK_CONTINUE_TOOLTIPS));

/** Type of a block that has CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN */
type CustomContextMenuBlock = Block&CustomContextMenuMixin;
interface CustomContextMenuMixin extends CustomContextMenuMixinType {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Semicolon not needed:

Suggested change
interface CustomContextMenuMixin extends CustomContextMenuMixinType {};
interface CustomContextMenuMixin extends CustomContextMenuMixinType {}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

blocks/loops.ts Outdated

/** Type of a block that has CONTROL_FLOW_IN_LOOP_CHECK_MIXIN */
type ControlFlowInLoopBlock = Block&ControlFlowInLoopMixin;
interface ControlFlowInLoopMixin extends ControlFlowInLoopMixinType {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Semicolon not needed:

Suggested change
interface ControlFlowInLoopMixin extends ControlFlowInLoopMixinType {};
interface ControlFlowInLoopMixin extends ControlFlowInLoopMixinType {}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@rachel-fenichel rachel-fenichel merged commit a4d0b67 into google:develop Apr 18, 2023
@rachel-fenichel rachel-fenichel deleted the convert_loops branch April 18, 2023 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants