Dots in class selectors are missing from the output #14

Closed
opened 2025-01-24 13:25:44 +01:00 by SirPepe · 5 comments
SirPepe commented 2025-01-24 13:25:44 +01:00 (Migrated from github.com)
import { parser } from "@lezer/css";
import { printTree } from "@lezer-unofficial/printer";
const source = ".foo {}";
const tree = parser.parse(source);
console.log(printTree(tree, source));

Results in the ClassSelector containing only the class name, but not the dot:

StyleSheet [1:0..1:7]
┗━  RuleSet [1:0..1:7]
    ┣━  ClassSelector [1:0..1:4]
    ┃   ┗━  ClassName [1:1..1:4]: "foo"
    ┗━  Block [1:5..1:7]
        ┣━  { [1:5..1:6]: "{"
        ┗━  } [1:6..1:7]: "}"

With an ID selector for comparison:

StyleSheet [1:0..1:7]
┗━  RuleSet [1:0..1:7]
    ┣━  IdSelector [1:0..1:4]
    ┃   ┣━  # [1:0..1:1]: "#"
    ┃   ┗━  IdName [1:1..1:4]: "foo"
    ┗━  Block [1:5..1:7]
        ┣━  { [1:5..1:6]: "{"
        ┗━  } [1:6..1:7]: "}"
```js import { parser } from "@lezer/css"; import { printTree } from "@lezer-unofficial/printer"; const source = ".foo {}"; const tree = parser.parse(source); console.log(printTree(tree, source)); ``` Results in the ClassSelector containing only the class name, but not the dot: ``` StyleSheet [1:0..1:7] ┗━ RuleSet [1:0..1:7] ┣━ ClassSelector [1:0..1:4] ┃ ┗━ ClassName [1:1..1:4]: "foo" ┗━ Block [1:5..1:7] ┣━ { [1:5..1:6]: "{" ┗━ } [1:6..1:7]: "}" ``` With an ID selector for comparison: ``` StyleSheet [1:0..1:7] ┗━ RuleSet [1:0..1:7] ┣━ IdSelector [1:0..1:4] ┃ ┣━ # [1:0..1:1]: "#" ┃ ┗━ IdName [1:1..1:4]: "foo" ┗━ Block [1:5..1:7] ┣━ { [1:5..1:6]: "{" ┗━ } [1:6..1:7]: "}" ```
marijnh commented 2025-01-24 14:16:04 +01:00 (Migrated from github.com)

Again, the ClassSelector node covers the dot and the name. The name is covered by another inner node. The dot is not missing, it just doesn't get a dedicated node, since it is easy enough to find or style with the existing structure.

Again, the `ClassSelector` node covers the dot and the name. The name is covered by another inner node. The dot is not missing, it just doesn't get a dedicated node, since it is easy enough to find or style with the existing structure.
SirPepe commented 2025-01-24 14:22:52 +01:00 (Migrated from github.com)

This does make sense, but why does the ID selector get treated differently?

This does make sense, but why does the ID selector get treated differently?
marijnh commented 2025-01-24 14:27:05 +01:00 (Migrated from github.com)

Indeed, that difference seems to be an accident. If it helps you, I can make "." a stored token as well.

Indeed, that difference seems to be an accident. If it helps you, I can make `"."` a stored token as well.
SirPepe commented 2025-01-24 14:29:09 +01:00 (Migrated from github.com)

This would make some things slightly less complicated on my side :) Thank you!

This would make some things slightly less complicated on my side :) Thank you!
marijnh commented 2025-01-24 14:33:44 +01:00 (Migrated from github.com)

Done in attached patch.

Done in attached patch.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/css#14
No description provided.