Skip to content

Commit a5a6158

Browse files
RobinMalfaitAutom3
andauthored
Improve candidate detection in minified JS arrays (without spaces) (#12396)
* add test to verify `["util1","util2"]` works * update extractor regex, to reduce valid values in the arbitrary value part Co-authored-by: Autom <[email protected]> * add special case with deeply nested `[]` * update changelog * move oxide changelog itemsto the bottom --------- Co-authored-by: Autom <[email protected]>
1 parent 1648b86 commit a5a6158

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272))
1313
- Don’t add spaces to negative numbers following a comma ([#12324](https://github.com/tailwindlabs/tailwindcss/pull/12324))
1414
- Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327))
15+
- Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342))
16+
- Improve candidate detection in minified JS arrays (without spaces) ([#12396](https://github.com/tailwindlabs/tailwindcss/pull/12396))
1517
- [Oxide] Remove `autoprefixer` dependency ([#11315](https://github.com/tailwindlabs/tailwindcss/pull/11315))
1618
- [Oxide] Fix source maps issue resulting in a crash ([#11319](https://github.com/tailwindlabs/tailwindcss/pull/11319))
1719
- [Oxide] Fallback to RegEx based parser when using custom transformers or extractors ([#11335](https://github.com/tailwindlabs/tailwindcss/pull/11335))
1820
- [Oxide] Bump `lightningcss` and reflect related improvements in tests ([#11550](https://github.com/tailwindlabs/tailwindcss/pull/11550))
19-
- Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342))
2021

2122
### Added
2223

src/lib/defaultExtractor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function* buildRegExps(context) {
4747
regex.any([
4848
regex.pattern([
4949
// Arbitrary values
50-
/-(?:\w+-)*\[[^\s:]+\]/,
50+
/-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/,
5151

5252
// Not immediately followed by an `{[(`
5353
/(?![{([]])/,
@@ -58,7 +58,7 @@ function* buildRegExps(context) {
5858

5959
regex.pattern([
6060
// Arbitrary values
61-
/-(?:\w+-)*\[[^\s]+\]/,
61+
/-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/,
6262

6363
// Not immediately followed by an `{[(`
6464
/(?![{([]])/,

tests/parse-candidate-strings.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -482,5 +482,19 @@ describe.each([
482482
expect(extractions).toContain(value)
483483
}
484484
})
485+
486+
it.each([
487+
['["min-w-[17rem]","max-w-[17rem]"]', ['min-w-[17rem]', 'max-w-[17rem]']],
488+
[
489+
'["w-[calc(theme(spacing[2]*-1px))]","h-[calc(theme(spacing[2]*-1px))]"]',
490+
['w-[calc(theme(spacing[2]*-1px))]', 'h-[calc(theme(spacing[2]*-1px))]'],
491+
],
492+
])('should work for issue #12371 (%#)', async (content, expectations) => {
493+
let extractions = parse(content)
494+
495+
for (let value of expectations) {
496+
expect(extractions).toContain(value)
497+
}
498+
})
485499
})
486500
})

0 commit comments

Comments
 (0)