Skip to content

Commit f57c2f9

Browse files
RobinMalfaitthecrypticace
authored andcommitted
Improve RegEx parser, reduce possibilities as the key for arbitrary properties (#12121)
* optimize handling of RegEx parser results Previous: - Copy `results`, for every subsequent result of other `patterns` - Loop over results to filter out `undefined` values - Loop over results to map to `clipAtBalancedParens` Current: - For each candidate, push the `clipAtBalancedParens(candidate)` into the `results` This way we are not copying existing results, and we are also avoiding additional loops over the entire array to filter out `undefined` values and map to `clipAtBalancedParens`. * do not allow `]` in the first part of arbitrary properties ``` [foo:bar] ─┬─ └── This part cannot contain `]` ``` This is also a very targeted fix for when the arbitrary properties seem to match a large piece of text, but shouldn't * add real world tests for parsing candidate strings * sync package-lock.json * update changelog
1 parent 2c23b8d commit f57c2f9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Update types to work with `Node16` module resolution ([#12097](https://github.com/tailwindlabs/tailwindcss/pull/12097))
2424
- Don’t crash when important and parent selectors are equal in `@apply` ([#12112](https://github.com/tailwindlabs/tailwindcss/pull/12112))
2525
- Eliminate irrelevant rules when applying variants ([#12113](https://github.com/tailwindlabs/tailwindcss/pull/12113))
26+
- Improve RegEx parser, reduce possibilities as the key for arbitrary properties ([#12121](https://github.com/tailwindlabs/tailwindcss/pull/12121))
2627

2728
## [3.3.3] - 2023-07-13
2829

src/lib/defaultExtractor.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ export function defaultExtractor(context) {
1212
let results = []
1313

1414
for (let pattern of patterns) {
15-
results = [...results, ...(content.match(pattern) ?? [])]
15+
for (let result of content.match(pattern) ?? []) {
16+
results.push(clipAtBalancedParens(result))
17+
}
1618
}
1719

18-
return results.filter((v) => v !== undefined).map(clipAtBalancedParens)
20+
return results
1921
}
2022
}
2123

@@ -34,7 +36,7 @@ function* buildRegExps(context) {
3436
// This is a targeted fix to continue to allow theme()
3537
// with square brackets to work in arbitrary properties
3638
// while fixing a problem with the regex matching too much
37-
/\[[^\s:'"`]+:[^\s]+?\[[^\s]+\][^\s]+?\]/,
39+
/\[[^\s:'"`\]]+:[^\s]+?\[[^\s]+\][^\s]+?\]/,
3840

3941
// Utilities
4042
regex.pattern([

0 commit comments

Comments
 (0)