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
RobinMalfait and Autom3 authored Nov 10, 2023
1 parent 1648b86 commit a5a6158
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272))
- Don’t add spaces to negative numbers following a comma ([#12324](https://github.com/tailwindlabs/tailwindcss/pull/12324))
- Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327))
- 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))
- [Oxide] Remove `autoprefixer` dependency ([#11315](https://github.com/tailwindlabs/tailwindcss/pull/11315))
- [Oxide] Fix source maps issue resulting in a crash ([#11319](https://github.com/tailwindlabs/tailwindcss/pull/11319))
- [Oxide] Fallback to RegEx based parser when using custom transformers or extractors ([#11335](https://github.com/tailwindlabs/tailwindcss/pull/11335))
- [Oxide] Bump `lightningcss` and reflect related improvements in tests ([#11550](https://github.com/tailwindlabs/tailwindcss/pull/11550))
- Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342))

### Added

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/parse-candidate-strings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,5 +482,19 @@ describe.each([
expect(extractions).toContain(value)
}
})

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 = parse(content)

for (let value of expectations) {
expect(extractions).toContain(value)
}
})
})
})

0 comments on commit a5a6158

Please sign in to comment.