Skip to content

Commit 89470d2

Browse files
RobinMalfaitAutom3
authored andcommitted
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 e26a1ba commit 89470d2

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327))
1414
- Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272))
1515
- 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))
1617
- Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514))
1718
- Fix support for slashes in arbitrary modifiers ([#12515](https://github.com/tailwindlabs/tailwindcss/pull/12515))
1819
- Fix source maps of variant utilities that come from an `@layer` rule ([#12508](https://github.com/tailwindlabs/tailwindcss/pull/12508))

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/default-extractor.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,17 @@ test('arbitrary properties followed by square bracketed stuff', () => {
503503

504504
expect(extractions).toContain(`[display:inherit]`)
505505
})
506+
507+
it.each([
508+
['["min-w-[17rem]","max-w-[17rem]"]', ['min-w-[17rem]', 'max-w-[17rem]']],
509+
[
510+
'["w-[calc(theme(spacing[2]*-1px))]","h-[calc(theme(spacing[2]*-1px))]"]',
511+
['w-[calc(theme(spacing[2]*-1px))]', 'h-[calc(theme(spacing[2]*-1px))]'],
512+
],
513+
])('should work for issue #12371 (%#)', async (content, expectations) => {
514+
let extractions = defaultExtractor(content)
515+
516+
for (let value of expectations) {
517+
expect(extractions).toContain(value)
518+
}
519+
})

0 commit comments

Comments
 (0)