From 43cdf754d42c7f12d2da0b549898bfd63f38d4d6 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Thu, 16 May 2024 19:16:43 +0200 Subject: [PATCH] Interactivity API: Turn named capturing groups back into numbered ones inside `toVdom` (#61728) * Back to numbered capturing groups * Change attrValue to attributeValue * Move `attributeValue` initialization * Change `namespaceAndPath` to `regexResult` Co-authored-by: DAreRodz Co-authored-by: sirreal --- packages/interactivity/src/vdom.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/interactivity/src/vdom.ts b/packages/interactivity/src/vdom.ts index 30179209cca67..8d3e43ba1c836 100644 --- a/packages/interactivity/src/vdom.ts +++ b/packages/interactivity/src/vdom.ts @@ -32,7 +32,7 @@ const directiveParser = new RegExp( // the reference, separated by `::`, like `some-namespace::state.somePath`. // Namespaces can contain any alphanumeric characters, hyphens, underscores or // forward slashes. References don't have any restrictions. -const nsPathRegExp = /^(?[\w_\/-]+)::(?.+)$/; +const nsPathRegExp = /^([\w_\/-]+)::(.+)$/; export const hydratedIslands = new WeakSet(); @@ -88,6 +88,7 @@ export function toVdom( root: Node ): Array< ComponentChild > { for ( let i = 0; i < attributes.length; i++ ) { const attributeName = attributes[ i ].name; + const attributeValue = attributes[ i ].value; if ( attributeName[ fullPrefix.length ] && attributeName.slice( 0, fullPrefix.length ) === fullPrefix @@ -95,12 +96,9 @@ export function toVdom( root: Node ): Array< ComponentChild > { if ( attributeName === ignoreAttr ) { ignore = true; } else { - const regexCaptureGroups = nsPathRegExp.exec( - attributes[ i ].value - )?.groups; - const namespace = regexCaptureGroups?.namespace ?? null; - let value: any = - regexCaptureGroups?.value ?? attributes[ i ].value; + const regexResult = nsPathRegExp.exec( attributeValue ); + const namespace = regexResult?.[ 1 ] ?? null; + let value: any = regexResult?.[ 2 ] ?? attributeValue; try { value = value && JSON.parse( value ); } catch ( e ) {} @@ -121,7 +119,7 @@ export function toVdom( root: Node ): Array< ComponentChild > { } else if ( attributeName === 'ref' ) { continue; } - props[ attributeName ] = attributes[ i ].value; + props[ attributeName ] = attributeValue; } if ( ignore && ! island ) {