Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/blocks/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Internal

- Update `memize` to 2.1.1 ([#80764](https://github.com/WordPress/gutenberg/pull/80764)).
- Update `hpq` to 1.4.0 for its bundled TypeScript types ([#81199](https://github.com/WordPress/gutenberg/pull/81199)).

## 15.24.0 (2026-07-14)

Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"change-case": "^4.1.2",
"colord": "^2.9.3",
"fast-deep-equal": "^3.1.3",
"hpq": "^1.3.0",
"hpq": "^1.4.0",
"is-plain-object": "^5.0.0",
"marked": "^18.0.3",
"memize": "^2.1.1",
Expand Down
1 change: 0 additions & 1 deletion packages/blocks/src/api/matchers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
// @ts-expect-error `hpq` does not ship type declarations.
export { attr, prop, text, query } from 'hpq';

/**
Expand Down
31 changes: 18 additions & 13 deletions packages/blocks/src/api/parser/get-block-attributes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* External dependencies
*/
// @ts-expect-error `hpq` does not ship type declarations.
import { parse as hpqParse } from 'hpq';
import type { MatcherObj } from 'hpq';
import memoize from 'memize';

/**
Expand Down Expand Up @@ -39,9 +39,9 @@ import type { BlockAttribute, BlockType } from '../../types';
* @return Enhanced hpq matcher.
*/
export const toBooleanAttributeMatcher =
( matcher: ( value: unknown ) => unknown ) =>
( value: unknown ): boolean =>
matcher( value ) !== undefined;
( matcher: ( domNode: Element ) => unknown ) =>
( domNode: Element ): boolean =>
matcher( domNode ) !== undefined;

/**
* Returns true if value is of the given JSON schema type, or false otherwise.
Expand Down Expand Up @@ -205,12 +205,12 @@ export const matcherFromSource = memoize(
): ( ( domNode: Element ) => unknown ) | undefined => {
switch ( sourceConfig.source ) {
case 'attribute': {
let matcher = attr(
const matcher = attr(
sourceConfig.selector,
sourceConfig.attribute
sourceConfig.attribute!
);
if ( sourceConfig.type === 'boolean' ) {
matcher = toBooleanAttributeMatcher( matcher );
return toBooleanAttributeMatcher( matcher );
}
return matcher;
}
Expand All @@ -228,19 +228,24 @@ export const matcherFromSource = memoize(
case 'node':
return node( sourceConfig.selector );
case 'query':
/*
* Sub-matchers may be undefined for unknown source types. hpq
* tolerates this and matches such keys as undefined, but its
* types don't allow for it.
*/
const subMatchers = Object.fromEntries(
Object.entries( sourceConfig.query! ).map(
( [ key, subSourceConfig ] ) => [
key,
matcherFromSource( subSourceConfig ),
]
)
);
return query( sourceConfig.selector, subMatchers );
) as MatcherObj;
return query( sourceConfig.selector!, subMatchers );
case 'tag': {
const matcher = prop( sourceConfig.selector, 'nodeName' );
return ( domNode: Node ) =>
( matcher( domNode ) as string )?.toLowerCase();
return ( domNode: Element ) =>
matcher( domNode )?.toLowerCase();
}
default:
// eslint-disable-next-line no-console
Expand All @@ -259,8 +264,8 @@ export const matcherFromSource = memoize(
*
* @return Parsed DOM node.
*/
function parseHtml( innerHTML: string | Node ): Node {
return hpqParse( innerHTML, ( h: Node ) => h );
function parseHtml( innerHTML: string | Node ): Element {
return hpqParse( innerHTML as string | Element, ( h: Element ) => h );
}

/**
Expand Down
Loading