-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
fix: improve parsing of :nth-of-type(xn+b)
#9970
Conversation
🦋 Changeset detectedLatest commit: 9402b64 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@navorite is attempting to deploy a commit to the Svelte Team on Vercel. A member of the Team first needs to authorize it. |
Now that I see the fix of #9969:
I see a (valid) case of -x is also not allowed, nor +xn , which are both valid.I did not compile it, but I would think this would fix it: const REGEX_NTH_OF = /^\s*(even|odd|([+-]?[0-9]*n?(\s*[+-]\s*[0-9]+)?))(\s*(?=[,)])|\s+of\s+)/; |
The regex also allows for |
I've also noticed more problems with the original matcher. It should fail when matching (the 2nd & 3rd line also work in svelte 4, but they should not)
The new regex covers the correct cases only: So now it matches
but it doesn't match
|
:nth-of-type(xn+y)
:nth-of-type(xn+y)
matcher
:nth-of-type(xn+y)
matcher:nth-of-type(xn+b)
matcher
@dummdidumm Running the h1:nth-of-type(10n+1)
{
background: red;
}
h1:nth-of-type(+10n-1)
{
background: red;
} produces incorrect results, the we can ofcourse stop matching |
:nth-of-type(xn+b)
matcher:nth-of-type(xn+b)
correctly
:nth-of-type(xn+b)
correctly:nth-of-type(xn+b)
packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
closes #9969
this also fixes the following along the way:
the
+
innth-of-type(+xn-b)
would be parsed as a combinator.invalid cases like these are not allowed anymore:
Svelte 5 rewrite
Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint