You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: PARSER_RECOMMENDATIONS.md
+74-15Lines changed: 74 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,63 @@
2
2
3
3
Based on implementing the formatter, here are recommendations for improving the CSS parser to better support formatting and other tooling use cases.
4
4
5
-
## 1. Attribute Selector Flags
5
+
## 1. Parentheses in Value Expressions (CRITICAL)
6
+
7
+
**Current Issue:** Parentheses in value expressions (particularly in `calc()`, `clamp()`, `min()`, `max()`, etc.) are not preserved in the AST. The parser flattens expressions into a simple sequence of values and operators, losing all grouping information.
**Workaround:** Currently impossible. The formatter cannot reconstruct parentheses because the information is lost during parsing. Falling back to raw text defeats the purpose of having a structured AST.
56
+
57
+
**Priority:** CRITICAL - This is blocking the migration from csstree to wallace-css-parser, as it causes semantic changes to CSS that break user styles.
58
+
59
+
---
60
+
61
+
## 2. Attribute Selector Flags
6
62
7
63
**Current Issue:** Attribute selector flags (case-insensitive `i` and case-sensitive `s`) are not exposed as a property on `CSSNode`.
8
64
@@ -39,7 +95,7 @@ let content_match = text.match(/::[^(]+(\([^)]*\))/)
39
95
40
96
---
41
97
42
-
## 3. Pseudo-Class Content Type Indication
98
+
## 4. Pseudo-Class Content Type Indication
43
99
44
100
**Current Issue:** No way to distinguish what type of content a pseudo-class contains without hardcoding known pseudo-class names.
45
101
@@ -71,7 +127,7 @@ get pseudo_content_type(): PseudoContentType
71
127
72
128
---
73
129
74
-
## 4. Empty Parentheses Detection
130
+
## 5. Empty Parentheses Detection
75
131
76
132
**Current Issue:** When a pseudo-class has empty parentheses (e.g., `:nth-child()`), there's no indication in the AST that parentheses exist at all. `first_child` is null, so formatters can't distinguish `:nth-child` from `:nth-child()`.
77
133
@@ -93,7 +149,7 @@ get has_parentheses(): boolean // True even if content is empty
93
149
94
150
---
95
151
96
-
## 5. Legacy Pseudo-Element Detection
152
+
## 6. Legacy Pseudo-Element Detection
97
153
98
154
**Current Issue:** Legacy pseudo-elements (`:before`, `:after`, `:first-letter`, `:first-line`) can be written with single colons but should be normalized to double colons. Parser treats them as `NODE_SELECTOR_PSEUDO_CLASS` rather than `NODE_SELECTOR_PSEUDO_ELEMENT`.
99
155
@@ -113,7 +169,7 @@ if (name === 'before' || name === 'after' || name === 'first-letter' || name ===
113
169
114
170
---
115
171
116
-
## 6. Nth Expression Coefficient Normalization
172
+
## 7. Nth Expression Coefficient Normalization
117
173
118
174
**Current Issue:** Nth expressions like `-n` need to be normalized to `-1n` for consistency, but parser returns raw text.
119
175
@@ -134,7 +190,7 @@ else if (a === '+n') a = '+1n'
134
190
135
191
---
136
192
137
-
## 7. Pseudo-Class/Element Content as Structured Data
193
+
## 8. Pseudo-Class/Element Content as Structured Data
138
194
139
195
**Current Issue:** Content inside pseudo-classes like `:lang("en", "fr")` is not parsed into structured data. Must preserve as raw text.
0 commit comments