Skip to content

Change x-for to allow loops like (foo)in(bar) - #4897

Merged
calebporzio merged 1 commit into
alpinejs:mainfrom
ColonelThirtyTwo:more-flexible-x-for
Sep 9, 2026
Merged

Change x-for to allow loops like (foo)in(bar)#4897
calebporzio merged 1 commit into
alpinejs:mainfrom
ColonelThirtyTwo:more-flexible-x-for

Conversation

@ColonelThirtyTwo

Copy link
Copy Markdown
Contributor

Currently, the loop in x-for must have a space between the in/of and both the bindings and the source expression. However, JS doesn't require the space - only that they are separate tokens - so (item, index) in list may be minified to (item,index)in list which x-for no longer parses.

This patch alters the regular expression in parseForExpression to split the bindings and expression on word boundries (\b) rather than spaces, to support this syntax.

Currently, the loop in x-for must have a space between the in/of and both
the bindings and the source expression. However, JS doesn't require the
space - only that they are separate tokens - so `(item, index) in list`
may be minified to `(item,index)in list` which `x-for` no longer parses.

This patch alters the regular expression in `parseForExpression` to split
the bindings and expression on word boundries (`\b`) rather than spaces,
to support this syntax.
@ekwoka

ekwoka commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

I get it...but like why?

@ColonelThirtyTwo

Copy link
Copy Markdown
Contributor Author

In my app, I have a Rust macro that runs some basic minification over passed-in javascript, and it minifies (foo, bar) in baz to (foo,bar)in baz since it's technically legal. I could special case it, but I figure since it was a fairly straightforward change to Alpine to accept it, I'd submit it as a PR.

@calebporzio
calebporzio merged commit fd2658a into alpinejs:main Sep 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants