From 89470d29b4cd0f35989e41b84856fa3222a1c5c6 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 10 Nov 2023 23:06:02 +0100 Subject: [PATCH] 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 * add special case with deeply nested `[]` * update changelog * move oxide changelog itemsto the bottom --------- Co-authored-by: Autom --- CHANGELOG.md | 1 + src/lib/defaultExtractor.js | 4 ++-- tests/default-extractor.test.js | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 384e35bef151..705d1d7f0257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327)) - Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272)) - Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342)) +- Improve candidate detection in minified JS arrays (without spaces) ([#12396](https://github.com/tailwindlabs/tailwindcss/pull/12396)) - Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514)) - Fix support for slashes in arbitrary modifiers ([#12515](https://github.com/tailwindlabs/tailwindcss/pull/12515)) - Fix source maps of variant utilities that come from an `@layer` rule ([#12508](https://github.com/tailwindlabs/tailwindcss/pull/12508)) diff --git a/src/lib/defaultExtractor.js b/src/lib/defaultExtractor.js index 0751c1acba7e..75ee8af50f81 100644 --- a/src/lib/defaultExtractor.js +++ b/src/lib/defaultExtractor.js @@ -47,7 +47,7 @@ function* buildRegExps(context) { regex.any([ regex.pattern([ // Arbitrary values - /-(?:\w+-)*\[[^\s:]+\]/, + /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/, // Not immediately followed by an `{[(` /(?![{([]])/, @@ -58,7 +58,7 @@ function* buildRegExps(context) { regex.pattern([ // Arbitrary values - /-(?:\w+-)*\[[^\s]+\]/, + /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/, // Not immediately followed by an `{[(` /(?![{([]])/, diff --git a/tests/default-extractor.test.js b/tests/default-extractor.test.js index 05a19e62653f..bbf0960bd805 100644 --- a/tests/default-extractor.test.js +++ b/tests/default-extractor.test.js @@ -503,3 +503,17 @@ test('arbitrary properties followed by square bracketed stuff', () => { expect(extractions).toContain(`[display:inherit]`) }) + +it.each([ + ['["min-w-[17rem]","max-w-[17rem]"]', ['min-w-[17rem]', 'max-w-[17rem]']], + [ + '["w-[calc(theme(spacing[2]*-1px))]","h-[calc(theme(spacing[2]*-1px))]"]', + ['w-[calc(theme(spacing[2]*-1px))]', 'h-[calc(theme(spacing[2]*-1px))]'], + ], +])('should work for issue #12371 (%#)', async (content, expectations) => { + let extractions = defaultExtractor(content) + + for (let value of expectations) { + expect(extractions).toContain(value) + } +})