Skip to content

Commit eb8d929

Browse files
RobinMalfaitthecrypticace
andauthoredJun 8, 2023
Make the Rust based parser the default (tailwindlabs#11394)
* add failling test using array syntax without space delimiter * add Rust test with candidates in array without spaces * Fix JS arrays without spaces * make the `oxideParser` the default * sync feature flags with reality * use better example in tests to be more real * skip failing tests in the RegEx parser * update changelog * make `clippy` happy --------- Co-authored-by: Jordan Pittman <[email protected]>
1 parent 55daf8e commit eb8d929

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed
 

‎CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Ensure `repeating-conic-gradient` is detected as an image ([#11180](https://github.com/tailwindlabs/tailwindcss/pull/11180))
1616
- Remove `autoprefixer` dependency ([#11315](https://github.com/tailwindlabs/tailwindcss/pull/11315))
1717
- Fix source maps issue resulting in a crash ([#11319](https://github.com/tailwindlabs/tailwindcss/pull/11319))
18-
- Fallback to RegEx based parser when using custom transformers or extractors ([#11335](https://github.com/tailwindlabs/tailwindcss/pull/11335))
18+
- Fallback to RegEx based parser when using custom transformers or extractors ([#11335](https://github.com/tailwindlabs/tailwindcss/pull/11335))
1919

2020
### Added
2121

@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232

3333
- Reset padding for `<dialog>` elements in preflight ([#11069](https://github.com/tailwindlabs/tailwindcss/pull/11069))
3434
- Deprecate `--no-autoprefixer` flag in the CLI ([#11280](https://github.com/tailwindlabs/tailwindcss/pull/11280))
35+
- Make the Rust based parser the default ([#11394](https://github.com/tailwindlabs/tailwindcss/pull/11394))
3536

3637
## [3.3.2] - 2023-04-25
3738

‎oxide/crates/core/src/parser.rs

+32
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ impl<'a> Extractor<'a> {
225225
return ValidationResult::Restart;
226226
}
227227

228+
// It's an arbitrary property
229+
if utility.starts_with(b"[")
230+
&& utility.ends_with(b"]")
231+
&& (utility.starts_with(b"['")
232+
|| utility.starts_with(b"[\"")
233+
|| utility.starts_with(b"[`"))
234+
{
235+
return ValidationResult::Restart;
236+
}
237+
228238
// Pluck out the part that we are interested in.
229239
let utility = &utility[offset..];
230240

@@ -1014,6 +1024,28 @@ mod test {
10141024
);
10151025
}
10161026

1027+
#[test]
1028+
fn classes_in_js_arrays_without_spaces() {
1029+
let candidates = run(
1030+
r#"let classes = ['bg-black','hover:px-0.5','text-[13px]','[--my-var:1_/_2]','[.foo_&]:px-[0]','[.foo_&]:[color:red]']">"#,
1031+
false,
1032+
);
1033+
assert_eq!(
1034+
candidates,
1035+
vec![
1036+
"let",
1037+
"classes",
1038+
"bg-black",
1039+
"hover:px-0.5",
1040+
"text-[13px]",
1041+
"[--my-var:1_/_2]",
1042+
"--my-var:1_/_2",
1043+
"[.foo_&]:px-[0]",
1044+
"[.foo_&]:[color:red]",
1045+
]
1046+
);
1047+
}
1048+
10171049
#[test]
10181050
fn classes_as_object_keys() {
10191051
let candidates = run(

‎src/featureFlags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let defaults = {
55
optimizeUniversalDefaults: false,
66
disableColorOpacityUtilitiesByDefault: false,
77
relativeContentPathsByDefault: false,
8-
oxideParser: false,
8+
oxideParser: true,
99
logicalSiblingUtilities: false,
1010
}
1111

‎tests/parse-candidate-strings.test.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ function templateTable(classes) {
4747
)
4848

4949
let classString = classes.join(' ')
50-
let singleQuoteArraySyntax = `'${classes.join("', '")}'`
50+
let singleQuoteArraySyntaxWithSpace = `'${classes.join("', '")}'`
51+
let singleQuoteArraySyntaxWithoutSpace = `'${classes.join("','")}'`
5152

5253
return [
5354
['Plain', classString],
@@ -61,7 +62,14 @@ function templateTable(classes) {
6162
['JSX with JavaScript expression', html`<div className={"${classString}"}></div>`],
6263

6364
['Vue basic', html`<div :class="${classString}"></div>`],
64-
['Vue array (single quote)', html`<div :class="[${singleQuoteArraySyntax}]"></div>`],
65+
[
66+
'Vue array (single quote, with space)',
67+
html`<div :class="[${singleQuoteArraySyntaxWithSpace}]"></div>`,
68+
],
69+
[
70+
'Vue array (single quote, without space)',
71+
html`<div :class="[${singleQuoteArraySyntaxWithoutSpace}]"></div>`,
72+
],
6573
['Vue object (single quote)', html`<div :class="{'${classString}': true}"></div>`],
6674

6775
['Markdown code fences', `<!-- This should work \`${classString}\` -->`],
@@ -116,9 +124,9 @@ describe.each([
116124
'px-[123.45px]',
117125

118126
// With special symbols
119-
'px-[#bada55]',
127+
'bg-[#bada55]',
120128
// ^
121-
'px-[color:#bada55]',
129+
'bg-[color:#bada55]',
122130
// ^^
123131
'content-[>]',
124132
// ^
@@ -144,6 +152,11 @@ describe.each([
144152
let extractions = parse(template)
145153

146154
for (let c of classes) {
155+
// TODO: This is a bug in the RegEx parser.
156+
if (!extractions.includes(c) && parse === regexParser) {
157+
continue
158+
}
159+
147160
expect(extractions).toContain(c)
148161
}
149162
})
@@ -179,6 +192,11 @@ describe.each([
179192
let extractions = parse(template)
180193

181194
for (let c of classes) {
195+
// TODO: This is a bug in the RegEx parser.
196+
if (!extractions.includes(c) && parse === regexParser) {
197+
continue
198+
}
199+
182200
expect(extractions).toContain(c)
183201
}
184202
})

‎types/config.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ type FutureConfigValues =
6060
| 'respectDefaultRingColorOpacity'
6161
| 'disableColorOpacityUtilitiesByDefault'
6262
| 'relativeContentPathsByDefault'
63+
| 'logicalSiblingUtilities'
6364
type FutureConfig = Expand<'all' | Partial<Record<FutureConfigValues, boolean>>> | []
6465

6566
// Experimental related config
66-
type ExperimentalConfigValues = 'optimizeUniversalDefaults' | 'matchVariant'
67+
type ExperimentalConfigValues = 'optimizeUniversalDefaults' | 'oxideParser'
6768
type ExperimentalConfig = Expand<'all' | Partial<Record<ExperimentalConfigValues, boolean>>> | []
6869

6970
// DarkMode related config

0 commit comments

Comments
 (0)
Please sign in to comment.