Skip to content

Commit

Permalink
Improve candidate detection in minified JS arrays (without spaces) (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
2 people authored and thecrypticace committed Dec 4, 2023
1 parent e26a1ba commit 89470d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/lib/defaultExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function* buildRegExps(context) {
regex.any([
regex.pattern([
// Arbitrary values
/-(?:\w+-)*\[[^\s:]+\]/,
/-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/,

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

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

// Not immediately followed by an `{[(`
/(?![{([]])/,
Expand Down
14 changes: 14 additions & 0 deletions tests/default-extractor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

0 comments on commit 89470d2

Please sign in to comment.