Skip to content

Commit 175f793

Browse files
committed
fix: break out of arbitrary value on whitespace
1 parent f98a582 commit 175f793

File tree

2 files changed

+82
-3
lines changed

2 files changed

+82
-3
lines changed

src/parser.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,85 @@ const test = suite('Parser')
7878
},
7979
],
8080
],
81+
[
82+
'[lang]:underline',
83+
[
84+
{
85+
raw: 'underline',
86+
value: '[lang]:underline',
87+
name: 'underline',
88+
prefix: '',
89+
important: false,
90+
negated: false,
91+
loc: { start: 7, end: 16 },
92+
spans: [{ start: 0, end: 16 }],
93+
variants: [{ name: '[lang]', raw: '[lang]:', value: '[lang]:', loc: { start: 0, end: 7 } }],
94+
},
95+
],
96+
],
97+
// Invalid arbitray value
98+
[
99+
'text-[hsl(100, 50%, 10%)]',
100+
[
101+
{
102+
raw: 'text-[hsl(100,',
103+
value: 'text-[hsl(100,',
104+
name: 'text-[hsl(100,',
105+
prefix: '',
106+
important: false,
107+
negated: false,
108+
loc: {
109+
start: 0,
110+
end: 14,
111+
},
112+
spans: [
113+
{
114+
start: 0,
115+
end: 14,
116+
},
117+
],
118+
variants: [],
119+
},
120+
{
121+
raw: '50%,',
122+
value: '50%,',
123+
name: '50%,',
124+
prefix: '',
125+
important: false,
126+
negated: false,
127+
loc: {
128+
start: 15,
129+
end: 19,
130+
},
131+
spans: [
132+
{
133+
start: 15,
134+
end: 19,
135+
},
136+
],
137+
variants: [],
138+
},
139+
{
140+
raw: '10%)]',
141+
value: '10%)]',
142+
name: '10%)]',
143+
prefix: '',
144+
important: false,
145+
negated: false,
146+
loc: {
147+
start: 20,
148+
end: 25,
149+
},
150+
spans: [
151+
{
152+
start: 20,
153+
end: 25,
154+
},
155+
],
156+
variants: [],
157+
},
158+
],
159+
],
81160
[
82161
'-mx-5!',
83162
[

src/parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,16 @@ export function astish(text: string, atPosition = Infinity): Group {
279279
let parent: Exclude<Node, null> = root
280280
let node: Exclude<Node, null> = root
281281

282-
for (let char: string, dynamic = false, position = 0; (char = text[position]); position++) {
282+
for (let char: string, inArbitrary = false, position = 0; (char = text[position]); position++) {
283283
if (position >= atPosition) {
284284
node.next = createIdentifier(node, parent, buffer, start)
285285

286286
return root
287287
}
288288

289-
if (dynamic || char == '[') {
289+
if ((inArbitrary && !/\s/.test(char)) || char == '[') {
290290
buffer += char
291-
dynamic = char != ']'
291+
inArbitrary = char != ']'
292292
continue
293293
}
294294

0 commit comments

Comments
 (0)