Open
feat: add support for class prefix selectors (.foo-*)#333
Conversation
Closes #332 Co-authored-by: MoOx <157534+MoOx@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for .foo-* class prefix selectors
feat: add support for class prefix selectors (.foo-*)
Aug 7, 2026
Collaborator
|
@romainmenke any feedback for this? |
There was a problem hiding this comment.
Pull request overview
Adds parsing support for CSS “class prefix selectors” of the form .foo-*, intending to treat them as a single class node (value foo-*) instead of splitting into class + universal.
Changes:
- Update
splitWord()to optionally consume a trailing*token into a class-like word ending in-. - Add new test cases covering
.foo-*,div.foo-*, and.foo-*.bar-*. - Bump the lockfile version metadata (package-lock.json) to
7.1.5.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/parser.js | Extends splitWord() to fold * into .foo- words and adjust token reference used for source calculations. |
| src/tests/classes.mjs | Adds new class-prefix selector parsing assertions. |
| package-lock.json | Updates package version fields to 7.1.5. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
965
to
975
| let indices = sortAsc(uniqs([0, ...hasClass, ...hasId])); | ||
| indices.forEach((ind, i) => { | ||
| const index = indices[i + 1] || word.length; | ||
| const value = word.slice(ind, index); | ||
| if (i === 0 && firstCallback) { | ||
| return firstCallback.call(this, value, indices.length); | ||
| } | ||
| let node; | ||
| const current = this.currToken; | ||
| const current = wordStartToken; | ||
| const sourceIndex = current[TOKEN.START_POS] + indices[i]; | ||
| const source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1)); |
Comment on lines
+278
to
+295
| test("class prefix selector", ".foo-*", (t, tree) => { | ||
| t.deepEqual(tree.nodes[0].nodes[0].type, "class"); | ||
| t.deepEqual(tree.nodes[0].nodes[0].value, "foo-*"); | ||
| }); | ||
|
|
||
| test("class prefix selector with tag", "div.foo-*", (t, tree) => { | ||
| t.deepEqual(tree.nodes[0].nodes[0].type, "tag"); | ||
| t.deepEqual(tree.nodes[0].nodes[0].value, "div"); | ||
| t.deepEqual(tree.nodes[0].nodes[1].type, "class"); | ||
| t.deepEqual(tree.nodes[0].nodes[1].value, "foo-*"); | ||
| }); | ||
|
|
||
| test("multiple class prefix selectors", ".foo-*.bar-*", (t, tree) => { | ||
| t.deepEqual(tree.nodes[0].nodes[0].type, "class"); | ||
| t.deepEqual(tree.nodes[0].nodes[0].value, "foo-*"); | ||
| t.deepEqual(tree.nodes[0].nodes[1].type, "class"); | ||
| t.deepEqual(tree.nodes[0].nodes[1].value, "bar-*"); | ||
| }); |
Contributor
|
I choose not to spend time reading or reviewing LLM generated content. |
Collaborator
|
Sure no problem. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds parsing support for CSS class prefix selectors per w3c/csswg-drafts#10001. A selector like
.foo-*now produces a single class AST node rather than being split into a class and universal selector.src/parser.js): InsplitWord(), when a word contains a class dot and ends with-, consume the following*token into the word. This produces a singleClassNamenode with the wildcard suffix.src/__tests__/classes.mjs): Added cases for.foo-*,div.foo-*, and.foo-*.bar-*.Note:
div-*(no class dot) still correctly produces tag + universal selector — the prefix logic only fires when a.class indicator is present in the word..foo-*class prefix selectors #332