Skip to content

Commit

Permalink
Fix class detection in Slim templates with attached attributes and IDs (
Browse files Browse the repository at this point in the history
#14019)

* Fix class detection in Slim templates with attached attributes and IDs

* Update changelog

* Tweak regex
  • Loading branch information
thecrypticace authored Jul 18, 2024
1 parent d622977 commit bdc87ae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
- Fix class detection in Slim templates with attached attributes and ID ([#14019](https://github.com/tailwindlabs/tailwindcss/pull/14019))

## [3.4.6] - 2024-07-16

Expand Down
3 changes: 3 additions & 0 deletions src/lib/defaultExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ function* buildRegExps(context) {
utility,
])
}

// 5. Inner matches
yield /[^<>"'`\s.(){}[\]#=%$][^<>"'`\s(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
}

// We want to capture any "special" characters
Expand Down
20 changes: 20 additions & 0 deletions tests/default-extractor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,26 @@ test('classes in slim templates starting with number', async () => {
expect(extractions).toContain('2xl:bg-red-300')
})

test('classes in slim templates with attributes added', () => {
let extractions = defaultExtractor(`
.ml-auto[
data-value='foo'
]
Foo bar
.mr-auto[data-value='foo']
Foo bar
.mt-auto#omg
Foo bar
#omg.mb-auto
Foo bar
`)

expect(extractions).toContain(`ml-auto`)
expect(extractions).toContain(`mr-auto`)
expect(extractions).toContain(`mt-auto`)
expect(extractions).toContain(`mb-auto`)
})

test("classes with fractional numeric values don't also generate the whole number utility", async () => {
const extractions = defaultExtractor(`
<div class="px-1.5 py-2.75">Hello world!</div>
Expand Down

0 comments on commit bdc87ae

Please sign in to comment.