Skip to content

Commit

Permalink
Keycodes: improve tree shaking by annotating exports as pure (#67615)
Browse files Browse the repository at this point in the history
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: sgomes <sergiomdgomes@git.wordpress.org>
  • Loading branch information
5 people authored Dec 5, 2024
1 parent 5644105 commit c99acaf
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions packages/keycodes/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ export const modifiers = {
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw
* shortcuts.
*/
export const rawShortcut = mapValues(
modifiers,
( /** @type {WPModifier} */ modifier ) => {
export const rawShortcut =
/* @__PURE__ */
mapValues( modifiers, ( /** @type {WPModifier} */ modifier ) => {
return /** @type {WPKeyHandler<string>} */ (
character,
_isApple = isAppleOS
Expand All @@ -222,8 +222,7 @@ export const rawShortcut = mapValues(
'+'
);
};
}
);
} );

/**
* Return an array of the parts of a keyboard shortcut chord for display.
Expand All @@ -238,9 +237,9 @@ export const rawShortcut = mapValues(
* @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to
* shortcut sequences.
*/
export const displayShortcutList = mapValues(
modifiers,
( /** @type {WPModifier} */ modifier ) => {
export const displayShortcutList =
/* @__PURE__ */
mapValues( modifiers, ( /** @type {WPModifier} */ modifier ) => {
return /** @type {WPKeyHandler<string[]>} */ (
character,
_isApple = isAppleOS
Expand Down Expand Up @@ -268,8 +267,7 @@ export const displayShortcutList = mapValues(

return [ ...modifierKeys, capitaliseFirstCharacter( character ) ];
};
}
);
} );

/**
* An object that contains functions to display shortcuts.
Expand All @@ -284,15 +282,17 @@ export const displayShortcutList = mapValues(
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
* display shortcuts.
*/
export const displayShortcut = mapValues(
displayShortcutList,
( /** @type {WPKeyHandler<string[]>} */ shortcutList ) => {
return /** @type {WPKeyHandler<string>} */ (
character,
_isApple = isAppleOS
) => shortcutList( character, _isApple ).join( '' );
}
);
export const displayShortcut =
/* @__PURE__ */
mapValues(
displayShortcutList,
( /** @type {WPKeyHandler<string[]>} */ shortcutList ) => {
return /** @type {WPKeyHandler<string>} */ (
character,
_isApple = isAppleOS
) => shortcutList( character, _isApple ).join( '' );
}
);

/**
* An object that contains functions to return an aria label for a keyboard
Expand All @@ -308,9 +308,9 @@ export const displayShortcut = mapValues(
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
* shortcut ARIA labels.
*/
export const shortcutAriaLabel = mapValues(
modifiers,
( /** @type {WPModifier} */ modifier ) => {
export const shortcutAriaLabel =
/* @__PURE__ */
mapValues( modifiers, ( /** @type {WPModifier} */ modifier ) => {
return /** @type {WPKeyHandler<string>} */ (
character,
_isApple = isAppleOS
Expand Down Expand Up @@ -338,8 +338,7 @@ export const shortcutAriaLabel = mapValues(
)
.join( isApple ? ' ' : ' + ' );
};
}
);
} );

/**
* From a given KeyboardEvent, returns an array of active modifier constants for
Expand Down Expand Up @@ -379,9 +378,9 @@ function getEventModifiers( event ) {
* @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions
* to match events.
*/
export const isKeyboardEvent = mapValues(
modifiers,
( /** @type {WPModifier} */ getModifiers ) => {
export const isKeyboardEvent =
/* @__PURE__ */
mapValues( modifiers, ( /** @type {WPModifier} */ getModifiers ) => {
return /** @type {WPEventKeyHandler} */ (
event,
character,
Expand Down Expand Up @@ -439,5 +438,4 @@ export const isKeyboardEvent = mapValues(

return key === character.toLowerCase();
};
}
);
} );

1 comment on commit c99acaf

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in c99acaf.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12179983421
📝 Reported issues:

Please sign in to comment.