Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Apr 30, 2024
1 parent 947d0a2 commit 0e0bf30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/interactivity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

- Hooks useMemo and useCallback should return a value. ([#60474](https://github.com/WordPress/gutenberg/pull/60474))

- Prevent wrong written directives from killing the runtime ([#61249](https://github.com/WordPress/gutenberg/pull/61249))

## 5.4.0 (2024-04-03)

## 5.3.0 (2024-03-21)
Expand Down
23 changes: 12 additions & 11 deletions packages/interactivity/src/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,31 @@ export function toVdom( root ) {
if ( directives.length ) {
props.__directives = directives.reduce(
( obj, [ name, ns, value ] ) => {
let [ prefix, suffix ] = [ '', 'default' ];

const directiveMatch = directiveParser.exec( name );
if ( directiveMatch ) {
const [ , _prefix, _suffix ] = directiveMatch;
prefix = _prefix;
suffix = _suffix ?? 'default';
} else if (
// @ts-expect-error
const prefix = directiveMatch ? directiveMatch[ 1 ] : '';
const suffix =
directiveMatch && directiveMatch[ 2 ]
? directiveMatch[ 2 ]
: 'default';

if (
! directiveMatch &&
// @ts-expect-error This is a debug-only warning.
typeof SCRIPT_DEBUG !== 'undefined' &&
// @ts-expect-error
SCRIPT_DEBUG === true
) {
// eslint-disable-next-line no-console
console.warn( `Invalid directive: ${ name }.` );
}
if ( ! obj[ prefix ] ) {
obj[ prefix ] = [];
}

obj[ prefix ] = obj[ prefix ] || [];
obj[ prefix ].push( {
namespace: ns ?? currentNamespace(),
value,
suffix,
} );

return obj;
},
{}
Expand Down

0 comments on commit 0e0bf30

Please sign in to comment.