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

Interactivity API: Turn named capturing groups back into numbered ones inside toVdom #61728

Merged
merged 4 commits into from
May 16, 2024
Merged
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
14 changes: 6 additions & 8 deletions packages/interactivity/src/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /^(?<namespace>[\w_\/-]+)::(?<value>.+)$/;
const nsPathRegExp = /^([\w_\/-]+)::(.+)$/;

export const hydratedIslands = new WeakSet();

Expand Down Expand Up @@ -88,19 +88,17 @@ 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
) {
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 ) {}
Expand All @@ -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 ) {
Expand Down
Loading