Skip to content

Commit b782d3a

Browse files
committed
more tests for the parser
1 parent 4bb17f0 commit b782d3a

13 files changed

Lines changed: 763 additions & 4 deletions

File tree

src/parse/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,16 @@ export const parse = (
228228
* Parse selector.
229229
*/
230230
function selector() {
231-
const m = /^([^{]+)/.exec(css);
232-
if (!m) {
231+
const bracePos = indexOfArrayWithBracketAndQuoteSupport(css, ['{']);
232+
if (bracePos === -1 || bracePos === 0) {
233233
return;
234234
}
235-
processMatch(m);
235+
const selectorStr = css.substring(0, bracePos);
236+
const fakeMatch = [selectorStr] as unknown as RegExpExecArray;
237+
processMatch(fakeMatch);
236238

237239
// remove comment in selector;
238-
const res = trim(m[0]).replace(commentRegex, '');
240+
const res = trim(selectorStr).replace(commentRegex, '');
239241

240242
return splitWithBracketAndQuoteSupport(res, [',']).map((v) => trim(v));
241243
}

test/cases/complex-nesting/ast.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

test/cases/complex-nesting/compressed.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
.dashboard {
2+
display: grid;
3+
gap: 1rem;
4+
5+
.sidebar {
6+
width: 250px;
7+
8+
nav {
9+
padding: 1rem;
10+
11+
a {
12+
color: inherit;
13+
text-decoration: none;
14+
15+
&:hover {
16+
text-decoration: underline;
17+
}
18+
19+
&::after {
20+
content: " \2192";
21+
}
22+
23+
&.active {
24+
font-weight: bold;
25+
26+
&::before {
27+
content: "\25B6";
28+
margin-right: 0.5em;
29+
}
30+
}
31+
}
32+
33+
ul {
34+
list-style: none;
35+
padding: 0;
36+
37+
> li {
38+
margin-bottom: 0.5rem;
39+
40+
+ li {
41+
border-top: 1px solid #eee;
42+
padding-top: 0.5rem;
43+
}
44+
}
45+
}
46+
}
47+
}
48+
49+
.main-content {
50+
flex: 1;
51+
52+
@media (min-width: 768px) {
53+
padding: 2rem;
54+
}
55+
56+
@media (min-width: 1024px) {
57+
padding: 3rem;
58+
59+
.hero {
60+
font-size: 2rem;
61+
}
62+
}
63+
64+
@supports (container-type: inline-size) {
65+
container-type: inline-size;
66+
67+
@container (min-width: 500px) {
68+
.card-grid {
69+
grid-template-columns: repeat(2, 1fr);
70+
}
71+
}
72+
}
73+
74+
h1 {
75+
font-size: 1.5rem;
76+
margin-bottom: 1rem;
77+
78+
~ p {
79+
color: #666;
80+
}
81+
}
82+
83+
.card {
84+
border: 1px solid #ddd;
85+
border-radius: 8px;
86+
padding: 1rem;
87+
88+
&:first-child {
89+
border-color: blue;
90+
}
91+
92+
&:not(:last-child) {
93+
margin-bottom: 1rem;
94+
}
95+
96+
.card-header {
97+
font-weight: bold;
98+
99+
.card-title {
100+
font-size: 1.2em;
101+
}
102+
103+
.card-subtitle {
104+
color: #999;
105+
font-size: 0.9em;
106+
}
107+
}
108+
109+
.card-body {
110+
margin-top: 0.5rem;
111+
}
112+
113+
.card-footer {
114+
margin-top: 1rem;
115+
border-top: 1px solid #eee;
116+
padding-top: 0.5rem;
117+
118+
button {
119+
cursor: pointer;
120+
121+
&:disabled {
122+
opacity: 0.5;
123+
cursor: not-allowed;
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
131+
@layer base {
132+
@layer reset {
133+
*, *::before, *::after {
134+
box-sizing: border-box;
135+
margin: 0;
136+
padding: 0;
137+
}
138+
}
139+
140+
@layer typography {
141+
body {
142+
font-family: system-ui, sans-serif;
143+
line-height: 1.5;
144+
145+
@media (prefers-color-scheme: dark) {
146+
color: #f0f0f0;
147+
background: #1a1a1a;
148+
}
149+
}
150+
}
151+
}
152+
153+
@scope (.theme-dark) to (.theme-light) {
154+
:scope {
155+
color: white;
156+
background: #333;
157+
158+
a {
159+
color: lightblue;
160+
161+
&:visited {
162+
color: plum;
163+
}
164+
}
165+
}
166+
167+
.card {
168+
background: #444;
169+
border-color: #555;
170+
171+
@media (prefers-contrast: high) {
172+
border-width: 2px;
173+
border-color: white;
174+
}
175+
}
176+
}
177+
178+
@media print {
179+
@page {
180+
margin: 2cm;
181+
182+
@top-center {
183+
content: "Printed Document";
184+
}
185+
186+
@bottom-center {
187+
content: counter(page) " / " counter(pages);
188+
}
189+
}
190+
191+
.dashboard {
192+
display: block;
193+
194+
.sidebar {
195+
display: none;
196+
}
197+
198+
.main-content {
199+
width: 100%;
200+
201+
.card {
202+
break-inside: avoid;
203+
page-break-inside: avoid;
204+
}
205+
}
206+
}
207+
}

0 commit comments

Comments
 (0)