Skip to content

Commit 564d878

Browse files
committed
fix(parse/tailwind): fix lexing inset-x, border-slate-500, and others
1 parent c9e20c3 commit 564d878

File tree

12 files changed

+27453
-2
lines changed

12 files changed

+27453
-2
lines changed

crates/biome_tailwind_parser/src/lexer/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,18 @@ impl<'src> TailwindLexer<'src> {
139139
.rfind(|&name| source_from_position.starts_with(name));
140140

141141
if let Some(base_name) = base_name {
142-
self.advance(base_name.len());
143-
return TW_BASE;
142+
// we need to make sure that either the base is followed by a `-` to signify a value is coming, or a whitespace/end of input to signify the end of the base
143+
match self.byte_at(base_name.len()) {
144+
Some(b'-') | None => {
145+
self.advance(base_name.len());
146+
return TW_BASE;
147+
}
148+
Some(b) if b.is_ascii_whitespace() => {
149+
self.advance(base_name.len());
150+
return TW_BASE;
151+
}
152+
_ => {}
153+
}
144154
}
145155

146156
while let Some(byte) = self.current_byte() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inset-x-[20px] inset-y-[15px]
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
source: crates/biome_tailwind_parser/tests/spec_test.rs
3+
expression: snapshot
4+
---
5+
## Input
6+
7+
```text
8+
inset-x-[20px] inset-y-[15px]
9+
10+
```
11+
12+
13+
## AST
14+
15+
```
16+
TwRoot {
17+
bom_token: missing (optional),
18+
candidates: TwCandidateList [
19+
TwFullCandidate {
20+
variants: TwVariantList [],
21+
negative_token: missing (optional),
22+
candidate: TwFunctionalCandidate {
23+
base_token: TW_BASE@0..7 "inset-x" [] [],
24+
minus_token: DASH@7..8 "-" [] [],
25+
value: TwArbitraryValue {
26+
l_brack_token: L_BRACKET@8..9 "[" [] [],
27+
value_token: TW_VALUE@9..13 "20px" [] [],
28+
r_brack_token: R_BRACKET@13..14 "]" [] [],
29+
},
30+
modifier: missing (optional),
31+
},
32+
excl_token: missing (optional),
33+
},
34+
WHITESPACE@14..15 " " [] [],
35+
TwFullCandidate {
36+
variants: TwVariantList [],
37+
negative_token: missing (optional),
38+
candidate: TwFunctionalCandidate {
39+
base_token: TW_BASE@15..22 "inset-y" [] [],
40+
minus_token: DASH@22..23 "-" [] [],
41+
value: TwArbitraryValue {
42+
l_brack_token: L_BRACKET@23..24 "[" [] [],
43+
value_token: TW_VALUE@24..28 "15px" [] [],
44+
r_brack_token: R_BRACKET@28..30 "]" [] [Newline("\n")],
45+
},
46+
modifier: missing (optional),
47+
},
48+
excl_token: missing (optional),
49+
},
50+
],
51+
eof_token: EOF@30..30 "" [] [],
52+
}
53+
```
54+
55+
## CST
56+
57+
```
58+
59+
0: (empty)
60+
61+
62+
63+
1: (empty)
64+
65+
0: [email protected] "inset-x" [] []
66+
1: [email protected] "-" [] []
67+
68+
0: [email protected] "[" [] []
69+
1: [email protected] "20px" [] []
70+
2: [email protected] "]" [] []
71+
3: (empty)
72+
3: (empty)
73+
1: [email protected] " " [] []
74+
75+
76+
1: (empty)
77+
78+
0: [email protected] "inset-y" [] []
79+
1: [email protected] "-" [] []
80+
81+
0: [email protected] "[" [] []
82+
1: [email protected] "15px" [] []
83+
2: [email protected] "]" [] [Newline("\n")]
84+
3: (empty)
85+
3: (empty)
86+
2: [email protected] "" [] []
87+
88+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
space-x-[14px] space-y-[10px] divide-x-[2px] divide-y-[3px]
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
source: crates/biome_tailwind_parser/tests/spec_test.rs
3+
expression: snapshot
4+
---
5+
## Input
6+
7+
```text
8+
space-x-[14px] space-y-[10px] divide-x-[2px] divide-y-[3px]
9+
10+
```
11+
12+
13+
## AST
14+
15+
```
16+
TwRoot {
17+
bom_token: missing (optional),
18+
candidates: TwCandidateList [
19+
TwFullCandidate {
20+
variants: TwVariantList [],
21+
negative_token: missing (optional),
22+
candidate: TwFunctionalCandidate {
23+
base_token: TW_BASE@0..7 "space-x" [] [],
24+
minus_token: DASH@7..8 "-" [] [],
25+
value: TwArbitraryValue {
26+
l_brack_token: L_BRACKET@8..9 "[" [] [],
27+
value_token: TW_VALUE@9..13 "14px" [] [],
28+
r_brack_token: R_BRACKET@13..14 "]" [] [],
29+
},
30+
modifier: missing (optional),
31+
},
32+
excl_token: missing (optional),
33+
},
34+
WHITESPACE@14..15 " " [] [],
35+
TwFullCandidate {
36+
variants: TwVariantList [],
37+
negative_token: missing (optional),
38+
candidate: TwFunctionalCandidate {
39+
base_token: TW_BASE@15..22 "space-y" [] [],
40+
minus_token: DASH@22..23 "-" [] [],
41+
value: TwArbitraryValue {
42+
l_brack_token: L_BRACKET@23..24 "[" [] [],
43+
value_token: TW_VALUE@24..28 "10px" [] [],
44+
r_brack_token: R_BRACKET@28..29 "]" [] [],
45+
},
46+
modifier: missing (optional),
47+
},
48+
excl_token: missing (optional),
49+
},
50+
WHITESPACE@29..30 " " [] [],
51+
TwFullCandidate {
52+
variants: TwVariantList [],
53+
negative_token: missing (optional),
54+
candidate: TwFunctionalCandidate {
55+
base_token: TW_BASE@30..38 "divide-x" [] [],
56+
minus_token: DASH@38..39 "-" [] [],
57+
value: TwArbitraryValue {
58+
l_brack_token: L_BRACKET@39..40 "[" [] [],
59+
value_token: TW_VALUE@40..43 "2px" [] [],
60+
r_brack_token: R_BRACKET@43..44 "]" [] [],
61+
},
62+
modifier: missing (optional),
63+
},
64+
excl_token: missing (optional),
65+
},
66+
WHITESPACE@44..45 " " [] [],
67+
TwFullCandidate {
68+
variants: TwVariantList [],
69+
negative_token: missing (optional),
70+
candidate: TwFunctionalCandidate {
71+
base_token: TW_BASE@45..53 "divide-y" [] [],
72+
minus_token: DASH@53..54 "-" [] [],
73+
value: TwArbitraryValue {
74+
l_brack_token: L_BRACKET@54..55 "[" [] [],
75+
value_token: TW_VALUE@55..58 "3px" [] [],
76+
r_brack_token: R_BRACKET@58..60 "]" [] [Newline("\n")],
77+
},
78+
modifier: missing (optional),
79+
},
80+
excl_token: missing (optional),
81+
},
82+
],
83+
eof_token: EOF@60..60 "" [] [],
84+
}
85+
```
86+
87+
## CST
88+
89+
```
90+
91+
0: (empty)
92+
93+
94+
95+
1: (empty)
96+
97+
0: [email protected] "space-x" [] []
98+
1: [email protected] "-" [] []
99+
100+
0: [email protected] "[" [] []
101+
1: [email protected] "14px" [] []
102+
2: [email protected] "]" [] []
103+
3: (empty)
104+
3: (empty)
105+
1: [email protected] " " [] []
106+
107+
108+
1: (empty)
109+
110+
0: [email protected] "space-y" [] []
111+
1: [email protected] "-" [] []
112+
113+
0: [email protected] "[" [] []
114+
1: [email protected] "10px" [] []
115+
2: [email protected] "]" [] []
116+
3: (empty)
117+
3: (empty)
118+
3: [email protected] " " [] []
119+
120+
121+
1: (empty)
122+
123+
0: [email protected] "divide-x" [] []
124+
1: [email protected] "-" [] []
125+
126+
0: [email protected] "[" [] []
127+
1: [email protected] "2px" [] []
128+
2: [email protected] "]" [] []
129+
3: (empty)
130+
3: (empty)
131+
5: [email protected] " " [] []
132+
133+
134+
1: (empty)
135+
136+
0: [email protected] "divide-y" [] []
137+
1: [email protected] "-" [] []
138+
139+
0: [email protected] "[" [] []
140+
1: [email protected] "3px" [] []
141+
2: [email protected] "]" [] [Newline("\n")]
142+
3: (empty)
143+
3: (empty)
144+
2: [email protected] "" [] []
145+
146+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
break-before-auto break-after-page mix-blend-normal
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
source: crates/biome_tailwind_parser/tests/spec_test.rs
3+
expression: snapshot
4+
---
5+
## Input
6+
7+
```text
8+
break-before-auto break-after-page mix-blend-normal
9+
10+
```
11+
12+
13+
## AST
14+
15+
```
16+
TwRoot {
17+
bom_token: missing (optional),
18+
candidates: TwCandidateList [
19+
TwFullCandidate {
20+
variants: TwVariantList [],
21+
negative_token: missing (optional),
22+
candidate: TwFunctionalCandidate {
23+
base_token: TW_BASE@0..12 "break-before" [] [],
24+
minus_token: DASH@12..13 "-" [] [],
25+
value: TwNamedValue {
26+
value_token: TW_VALUE@13..17 "auto" [] [],
27+
},
28+
modifier: missing (optional),
29+
},
30+
excl_token: missing (optional),
31+
},
32+
WHITESPACE@17..18 " " [] [],
33+
TwFullCandidate {
34+
variants: TwVariantList [],
35+
negative_token: missing (optional),
36+
candidate: TwFunctionalCandidate {
37+
base_token: TW_BASE@18..29 "break-after" [] [],
38+
minus_token: DASH@29..30 "-" [] [],
39+
value: TwNamedValue {
40+
value_token: TW_VALUE@30..34 "page" [] [],
41+
},
42+
modifier: missing (optional),
43+
},
44+
excl_token: missing (optional),
45+
},
46+
WHITESPACE@34..35 " " [] [],
47+
TwFullCandidate {
48+
variants: TwVariantList [],
49+
negative_token: missing (optional),
50+
candidate: TwFunctionalCandidate {
51+
base_token: TW_BASE@35..44 "mix-blend" [] [],
52+
minus_token: DASH@44..45 "-" [] [],
53+
value: TwNamedValue {
54+
value_token: TW_VALUE@45..52 "normal" [] [Newline("\n")],
55+
},
56+
modifier: missing (optional),
57+
},
58+
excl_token: missing (optional),
59+
},
60+
],
61+
eof_token: EOF@52..52 "" [] [],
62+
}
63+
```
64+
65+
## CST
66+
67+
```
68+
69+
0: (empty)
70+
71+
72+
73+
1: (empty)
74+
75+
0: [email protected] "break-before" [] []
76+
1: [email protected] "-" [] []
77+
78+
0: [email protected] "auto" [] []
79+
3: (empty)
80+
3: (empty)
81+
1: [email protected] " " [] []
82+
83+
84+
1: (empty)
85+
86+
0: [email protected] "break-after" [] []
87+
1: [email protected] "-" [] []
88+
89+
0: [email protected] "page" [] []
90+
3: (empty)
91+
3: (empty)
92+
3: [email protected] " " [] []
93+
94+
95+
1: (empty)
96+
97+
0: [email protected] "mix-blend" [] []
98+
1: [email protected] "-" [] []
99+
100+
0: [email protected] "normal" [] [Newline("\n")]
101+
3: (empty)
102+
3: (empty)
103+
2: [email protected] "" [] []
104+
105+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
border-slate-500 border-teal-600 border-solid

0 commit comments

Comments
 (0)