Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4: Allow hyphen character in regex pattern to use support queries as is #13596

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion packages/tailwindcss/src/variants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,15 @@ test('sorting `min` and `max` should sort by unit, then by value, then alphabeti

test('supports', () => {
expect(
run(['supports-gap:grid', 'supports-[display:grid]:flex', 'supports-[selector(A_>_B)]:flex']),
run([
'supports-gap:grid',
'supports-[display:grid]:flex',
'supports-[selector(A_>_B)]:flex',
'supports-[font-format(opentype)]:grid',
'supports-[(display:grid)_and_font-format(opentype)]:grid',
'supports-[font-tech(color-COLRv1)]:flex',
'supports-[--test]:flex',
]),
).toMatchInlineSnapshot(`
"@supports (gap: var(--tw)) {
.supports-gap\\:grid {
Expand All @@ -1306,6 +1314,30 @@ test('supports', () => {
.supports-\\[selector\\(A_\\>_B\\)\\]\\:flex {
display: flex;
}
}

@supports font-format(opentype) {
.supports-\\[font-format\\(opentype\\)\\]\\:grid {
display: grid;
}
}

@supports (display: grid) and font-format(opentype) {
.supports-\\[\\(display\\:grid\\)_and_font-format\\(opentype\\)\\]\\:grid {
display: grid;
}
}

@supports font-tech(color-COLRv1) {
.supports-\\[font-tech\\(color-COLRv1\\)\\]\\:flex {
display: flex;
}
}

@supports (--test: var(--tw)) {
.supports-\\[--test\\]\\:flex {
display: flex;
}
}"
`)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss/src/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export function createVariants(theme: Theme): Variants {
// When `supports-[...]:flex` is used, with `not()`, `and()` or
// `selector()`, then we know that want to use this directly as the
// supports condition as-is.
if (/^\w*\s*\(/.test(value)) {
if (/^[\w-]*\s*\(/.test(value)) {
// Chrome has a bug where `(condition1)or(condition2)` is not valid, but
// `(condition1) or (condition2)` is supported.
let query = value.replace(/\b(and|or|not)\b/g, ' $1 ')
Expand Down
Loading