tailwindcss/tests/arbitrary-variants.test.js

1387 lines
44 KiB
JavaScript
Raw Permalink Normal View History

import { crosscheck, run, html, css, defaults } from './util/run'
Oxide (#10252) * temporarily disable workflows * add oxide Our Rust related parts * use oxide - Setup the codebase to be able to use the Rust parts based on an environment variable: `OXIDE=1`. - Setup some tests that run both the non-Rust and Rust version in the same test. - Sort the candidates in a consistent way, to guarantee the order for now (especially in tests). - Reflect sorting related changes in tests. - Ensure tests run in both the Rust and non-Rust version. (Some tests are explicitly skipped when using the Rust version since we haven't implemented those features yet. These include: custom prefix, transformers and extractors). - `jest` -`OXIDE=1 jest` * remove into_par_iter where it doesn't make sense * cargo fmt * wip * enable tracing based on `DEBUG` env * improve CI for the Oxide build * sort test output This happened because the sorting happens in this branch, but changes happened on the `master` branch. * add failing tests I noticed that some of the tests were failing, and while looking at them, it happened because the tests were structured like this: ```html <div class=" backdrop-filter backdrop-filter-none backdrop-blur-lg backdrop-brightness-50 backdrop-contrast-0 backdrop-grayscale backdrop-hue-rotate-90 backdrop-invert backdrop-opacity-75 backdrop-saturate-150 backdrop-sepia " ></div> ``` This means that the class names themselves eventually end up like this: `backdrop-filter-none\n` -> (Notice the `\n`) /cc @thecrypticace * fix range to include `\n` * Include only unique values for tests Really, what we care about most is that the list contains every expected candidate. Not necessarily how many times it shows up because while many candidates will show up A LOT in a source text we’ll unique them before passing them back to anything that needs them * Fix failing tests * Don’t match empty arbitrary values * skip tests in oxide mode regarding custom separators in arbitrary variants * re-enable workflows * use `@tailwindcss/oxide` dependency * publish `tailwindcss@oxide` * drop prepublishOnly I don't think we actually need this anymore (or even want because this is trying to do things in CI that we don't want to happen. Aka, build the Oxide Rust code, it is already a dependency). * WIP * Defer to existing CLI for Oxide * Include new compiled typescript stuff when publishing * Move TS to ./src/oxide * Update scripts * Clean up tests for TS * copy `cli` to `oxide/cli` * make CLI files TypeScript files * drop --postcss flag * setup lightningcss * Remove autoprefixer and cssnano from oxide CLI * cleanup Rust code a little bit - Drop commented out code - Drop 500 fixture templates * sort test output * re-add `prepublishOnly` script * bump SWC dependencies in package-lock.json * pin `@swc` dependencies * ensure to install and build oxide * update all GitHub Workflows to reflect Oxide required changes * sort `content-resolution` integration tests * add `Release Insiders — Oxide` * setup turbo repo + remote caching * use `npx` to invoke `turbo` * setup unique/proper package names for integration tests * add missing `isomorphic-fetch` dependency * setup integration tests to use `turborepo` * scope tailwind tasks to root workspace * re-enable `node_modules` cache for integration tests * re-enable `node_modules` cache for main CI workflow * split cache for `main` and `oxide` node_modules * fix indent * split install dependencies so that they can be cached individually * improve GitHub actions caching * use correct path for oxide node_modules (crates/node) * ensure that `cargo install` always succeeds cargo install X, on CI will fail if it already exists. * figure out integration tests with turbo * tmp: use `npm` instead of `turbo` * disable `fail-fast` This will allow us to run integration tests so that it still caches the succesful ones. * YAML OH YAML, Y U WHITESPACE SENSITIVE * copy the oxide-ci workflow to release-oxide * make `oxide-ci` a normal CI workflow Without publishing * try to cache cargo and node_modules for the oxide build * configure turbo to run scripts in the root * explicitly skip failing test for the Oxide version * run oxide tests in CI * only use build script for root package * sync package-lock.json * do not cache node_modules for each individual integration * look for hoisted `.bin` * use turbo for caching build tailwind css in integration tests * Robin... * try to use the local binary first * skip installing integration test dependencies Should already be installed due to workspace usage * Robin... * drop `output.clean` * explicitly add `mini-css-extract-plugin` * drop oxide-ci, this is tested by proxy * ensure oxide build is used in integration tests This will ensure the `@tailwindcss/oxide` dependency is available (whether we use it or not). * setup Oxide shim in insiders release * add browserslist dependency * use `install:all` script name Just using `install` as a script name will be called when running `npm install`. Now that we marked the repo as a `workspace`, `npm install` will run install in all workspaces which is... not ideal. * tmp: enable insiders release in PRs Just to check if everything works before merging. Can be removed once tested. * don't cache node_modules? I feel there is some catch 22 going on here. We require `npm install` to build the `oxide/crates/node` version. But we also require `oxide/crates/node` for the `npm install` becaus of the dependency: `"@tailwindcss/oxide": "file:oxide/creates/node"` * try to use `oxide/crates/node` as part of the workspace * let's think about this Let's try and cache the `node_modules` and share as much as possible. However, some scripts still need to be installed specific to the OS. Running `npm install` locally doesn't throw away your `node_modules`, so if we just cache `node_modules` but also run `npm install` that should keep as much as possible and still improve install times since `node_modules` is already there. I think. * ensure generated `index.js` and `index.d.ts` files are considered outputs * use `npx napi` instead of `napi` directly * include all `package-lock.json` files * normalize caching further in all workflows * drop nested `package-lock.json` files * `npm uninstall mini-css-extract-plugin && npm install mini-css-extract-plugin --save-dev` * bump webpack-5 integration tests dependencies * only release insiders on `master` branch * tmp: let's figure out release insiders oxide * fix little typo * use Node 18 for Oxide Insiders * syncup package-lock.json * let's try node 16 Node 18 currently fails on `Build x86_64-unknown-linux-gnu (OXIDE)` Workflow. Install Node.JS output: ``` Environment details Warning: /__t/node/18.13.0/x64/bin/node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by /__t/node/18.13.0/x64/bin/node) /__t/node/18.13.0/x64/bin/node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by /__t/node/18.13.0/x64/bin/node) /__t/node/18.13.0/x64/bin/node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /__t/node/18.13.0/x64/bin/node) /__t/node/18.13.0/x64/bin/node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /__t/node/18.13.0/x64/bin/node) /__t/node/18.13.0/x64/bin/node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /__t/node/18.13.0/x64/bin/node) /__t/node/18.13.0/x64/bin/node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /__t/node/18.13.0/x64/bin/node) Warning: node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node) node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node) node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node) node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node) node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node) node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node) ``` * bump some Node versions * only release oxide insiders on `master` branch * don't cache `npm` * bump napi-rs Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2023-01-13 12:22:00 +01:00
crosscheck(({ stable, oxide }) => {
test('basic arbitrary variants', () => {
let config = {
content: [{ raw: html`<div class="[&>*]:underline"></div>` }],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&\>\*\]\:underline > * {
text-decoration-line: underline;
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('spaces in selector (using _)', () => {
let config = {
content: [
{
raw: html`<div class="[.a.b_&]:underline"></div>`,
},
],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.a.b .\[\.a\.b_\&\]\:underline {
text-decoration-line: underline;
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('arbitrary variants with modifiers', () => {
let config = {
content: [{ raw: html`<div class="dark:lg:hover:[&>*]:underline"></div>` }],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
@media (prefers-color-scheme: dark) {
@media (min-width: 1024px) {
.dark\:lg\:hover\:\[\&\>\*\]\:underline > :hover {
text-decoration-line: underline;
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
}
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('variants without & or an at-rule are ignored', () => {
let config = {
content: [
{
raw: html`
<div class="[div]:underline"></div>
<div class="[:hover]:underline"></div>
<div class="[wtf-bbq]:underline"></div>
<div class="[lol]:hover:underline"></div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
`)
})
})
test('arbitrary variants are sorted after other variants', () => {
let config = {
content: [{ raw: html`<div class="underline lg:underline [&>*]:underline"></div>` }],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.underline {
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
text-decoration-line: underline;
}
@media (min-width: 1024px) {
.lg\:underline {
text-decoration-line: underline;
}
}
.\[\&\>\*\]\:underline > * {
text-decoration-line: underline;
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('using the important modifier', () => {
let config = {
content: [{ raw: html`<div class="[&>*]:!underline"></div>` }],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&\>\*\]\:\!underline > * {
text-decoration-line: underline !important;
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('at-rules', () => {
let config = {
content: [{ raw: html`<div class="[@supports(what:ever)]:underline"></div>` }],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
@supports (what: ever) {
.\[\@supports\(what\:ever\)\]\:underline {
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
text-decoration-line: underline;
}
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('nested at-rules', () => {
let config = {
content: [
{
raw: html`<div class="[@media_screen{@media(hover:hover)}]:underline"></div>`,
},
],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
@media screen {
@media (hover: hover) {
.\[\@media_screen\{\@media\(hover\:hover\)\}\]\:underline {
text-decoration-line: underline;
}
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('at-rules with selector modifications', () => {
let config = {
content: [{ raw: html`<div class="[@media(hover:hover){&:hover}]:underline"></div>` }],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
@media (hover: hover) {
.\[\@media\(hover\:hover\)\{\&\:hover\}\]\:underline:hover {
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
text-decoration-line: underline;
}
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('nested at-rules with selector modifications', () => {
let config = {
content: [
{
raw: html`<div class="[@media_screen{@media(hover:hover){&:hover}}]:underline"></div>`,
},
],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
@media screen {
@media (hover: hover) {
.\[\@media_screen\{\@media\(hover\:hover\)\{\&\:hover\}\}\]\:underline:hover {
text-decoration-line: underline;
}
}
}
`)
})
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
test('attribute selectors', () => {
let config = {
content: [{ raw: html`<div class="[&[data-open]]:underline"></div>` }],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&\[data-open\]\]\:underline[data-open] {
text-decoration-line: underline;
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('multiple attribute selectors', () => {
let config = {
content: [
{ raw: html`<div class="[&[data-foo][data-bar]:not([data-baz])]:underline"></div>` },
],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&\[data-foo\]\[data-bar\]\:not\(\[data-baz\]\)\]\:underline[data-foo][data-bar]:not([data-baz]) {
text-decoration-line: underline;
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
oxide.test.todo('multiple attribute selectors with custom separator (1)')
stable.test('multiple attribute selectors with custom separator (1)', () => {
let config = {
separator: '__',
content: [
{ raw: html`<div class="[&[data-foo][data-bar]:not([data-baz])]__underline"></div>` },
],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&\[data-foo\]\[data-bar\]\:not\(\[data-baz\]\)\]__underline[data-foo][data-bar]:not([data-baz]) {
text-decoration-line: underline;
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
oxide.test.todo('multiple attribute selectors with custom separator (2)')
stable.test('multiple attribute selectors with custom separator (2)', () => {
let config = {
separator: '_@',
content: [
{ raw: html`<div class="[&[data-foo][data-bar]:not([data-baz])]_@underline"></div>` },
],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&\[data-foo\]\[data-bar\]\:not\(\[data-baz\]\)\]_\@underline[data-foo][data-bar]:not([data-baz]) {
text-decoration-line: underline;
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('with @apply', () => {
let config = {
content: [
{
raw: html`<div class="foo"></div>`,
},
],
corePlugins: { preflight: false },
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
let input = `
@tailwind base;
@tailwind components;
@tailwind utilities;
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
.foo {
@apply [@media_screen{@media(hover:hover){&:hover}}]:underline;
}
`
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
@media screen {
@media (hover: hover) {
.foo:hover {
text-decoration-line: underline;
}
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
}
}
`)
})
Arbitrary variants (#8299) * register arbitrary variants With the new `addVariant` API, we have a beautiful way of creating new variants. You can use it as: ```js addVariant('children', '& > *') ``` Now you can use the `children:` variant. The API uses a `&` as a reference for the candidate, which means that: ```html children:pl-4 ``` Will result in: ```css .children\:pl-4 > * { .. } ``` Notice that the `&` was replaced by `.children\:pl-4`. We can leverage this API to implement arbitrary variants, this means that you can write those `&>*` (Notice that we don't have spaces) inside a variant directly. An example of this can be: ```html <ul class="[&>*]:underline"> <li>A</li> <li>B</li> <li>C</li> </ul> ``` Which generates the following css: ```css .\[\&\>\*\]\:underline > * { text-decoration-line: underline; } ``` Now all the children of the `ul` will have an `underline`. The selector itself is a bit crazy since it contains the candidate which is the selector itself, it is just escaped. * add tests for arbitrary variants This still requires some work to the `defaultExtractor` to make sure it all works with existing code. * update changelog * Fix candidate detection for arbitrary variants * Refactor * Add support for at rules * Add test for attribute selectors * Fix test * Add attribute selector support * Split top-level comma parsing into a generalized splitting routine We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough” * Split variants by separator at the top-level only This means that the separator has to be ouside of balanced brackets * Fix extraction when using custom variant separators * Support custom separators when top-level splitting variants * Add a second multi-character separator test * Split tests for at-rule and at-rule with selector changes * Add nested at-rule tests * Fix space-less at-rule parsing in addVariant * Add test for using with `@apply` Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 18:24:59 +02:00
})
test('keeps escaped underscores', () => {
let config = {
content: [
{
raw: '<div class="[&_.foo\\_\\_bar]:underline"></div>',
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&_\.foo\\_\\_bar\]\:underline .foo__bar {
text-decoration-line: underline;
}
`)
})
})
test('keeps escaped underscores with multiple arbitrary variants', () => {
let config = {
content: [
{
raw: '<div class="[&_.foo\\_\\_bar]:[&_.bar\\_\\_baz]:underline"></div>',
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&_\.foo\\_\\_bar\]\:\[\&_\.bar\\_\\_baz\]\:underline .bar__baz .foo__bar {
text-decoration-line: underline;
}
`)
})
})
test('keeps escaped underscores in arbitrary variants mixed with normal variants', () => {
let config = {
content: [
{
raw: `
<div class="[&_.foo\\_\\_bar]:hover:underline"></div>
<div class="hover:[&_.foo\\_\\_bar]:underline"></div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&_\.foo\\_\\_bar\]\:hover\:underline:hover .foo__bar,
.hover\:\[\&_\.foo\\_\\_bar\]\:underline .foo__bar:hover {
text-decoration-line: underline;
}
`)
})
})
test('allows attribute variants with quotes', () => {
let config = {
content: [
{
raw: `
<div class="[&[data-test='2']]:underline"></div>
<div class='[&[data-test="2"]]:underline'></div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
.\[\&\[data-test\=\"2\"\]\]\:underline[data-test='2'],
.\[\&\[data-test\=\'2\'\]\]\:underline[data-test='2'] {
text-decoration-line: underline;
}
`)
})
})
test('classes in arbitrary variants should not be prefixed', () => {
let config = {
prefix: 'tw-',
content: [
{
raw: `
<div class="[.foo_&]:tw-text-red-400">should not be red</div>
<div class="foo">
<div class="[.foo_&]:tw-text-red-400">should be red</div>
</div>
<div class="[&_.foo]:tw-text-red-400">
<div>should not be red</div>
<div class="foo">should be red</div>
</div>
<div class="hover:[&_.foo]:tw-text-red-400">
<div>should not be red</div>
<div class="foo">should be red</div>
</div>
<div class="[&_.foo]:hover:tw-text-red-400">
<div>should not be red</div>
<div class="foo">should be red</div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
stable.expect(result.css).toMatchFormattedCss(css`
.\[\&_\.foo\]\:tw-text-red-400 .foo,
.\[\&_\.foo\]\:hover\:tw-text-red-400:hover .foo,
.hover\:\[\&_\.foo\]\:tw-text-red-400 .foo:hover,
.foo .\[\.foo_\&\]\:tw-text-red-400 {
--tw-text-opacity: 1;
color: rgb(248 113 113 / var(--tw-text-opacity));
}
`)
oxide.expect(result.css).toMatchFormattedCss(css`
.\[\&_\.foo\]\:tw-text-red-400 .foo,
.\[\&_\.foo\]\:hover\:tw-text-red-400:hover .foo,
.hover\:\[\&_\.foo\]\:tw-text-red-400 .foo:hover,
.foo .\[\.foo_\&\]\:tw-text-red-400 {
color: #f87171;
}
`)
})
})
test('classes in the same arbitrary variant should not be prefixed', () => {
let config = {
prefix: 'tw-',
content: [
{
raw: `
<div class="[.foo_&]:tw-text-red-400 [.foo_&]:tw-bg-white">should not be red</div>
<div class="foo">
<div class="[.foo_&]:tw-text-red-400 [.foo_&]:tw-bg-white">should be red</div>
</div>
<div class="[&_.foo]:tw-text-red-400 [&_.foo]:tw-bg-white">
<div>should not be red</div>
<div class="foo">should be red</div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
stable.expect(result.css).toMatchFormattedCss(css`
.\[\&_\.foo\]\:tw-bg-white .foo {
--tw-bg-opacity: 1;
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}
.\[\&_\.foo\]\:tw-text-red-400 .foo {
--tw-text-opacity: 1;
color: rgb(248 113 113 / var(--tw-text-opacity));
}
.foo .\[\.foo_\&\]\:tw-bg-white {
--tw-bg-opacity: 1;
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}
.foo .\[\.foo_\&\]\:tw-text-red-400 {
--tw-text-opacity: 1;
color: rgb(248 113 113 / var(--tw-text-opacity));
}
`)
oxide.expect(result.css).toMatchFormattedCss(css`
.\[\&_\.foo\]\:tw-bg-white .foo {
background-color: #fff;
}
.\[\&_\.foo\]\:tw-text-red-400 .foo {
color: #f87171;
}
.foo .\[\.foo_\&\]\:tw-bg-white {
background-color: #fff;
}
.foo .\[\.foo_\&\]\:tw-text-red-400 {
color: #f87171;
}
`)
})
})
it('should support aria variants', () => {
let config = {
content: [
{
raw: html`
<div>
<div class="aria-checked:underline"></div>
<div class="aria-[sort=ascending]:underline"></div>
<div class="aria-[labelledby='a_b']:underline"></div>
<div class="group-aria-checked:underline"></div>
<div class="peer-aria-checked:underline"></div>
<div class="group-aria-checked/foo:underline"></div>
<div class="peer-aria-checked/foo:underline"></div>
<div class="group-aria-[sort=ascending]:underline"></div>
<div class="peer-aria-[sort=ascending]:underline"></div>
<div class="group-aria-[labelledby='a_b']:underline"></div>
<div class="peer-aria-[labelledby='a_b']:underline"></div>
<div class="group-aria-[sort=ascending]/foo:underline"></div>
<div class="peer-aria-[sort=ascending]/foo:underline"></div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
stable.expect(result.css).toMatchFormattedCss(css`
.underline,
.aria-checked\:underline[aria-checked='true'],
.aria-\[labelledby\=\'a_b\'\]\:underline[aria-labelledby='a b'],
.aria-\[sort\=ascending\]\:underline[aria-sort='ascending'],
.group\/foo[aria-checked='true'] .group-aria-checked\/foo\:underline,
.group[aria-checked='true'] .group-aria-checked\:underline,
.group[aria-labelledby='a b'] .group-aria-\[labelledby\=\'a_b\'\]\:underline,
.group\/foo[aria-sort='ascending'] .group-aria-\[sort\=ascending\]\/foo\:underline,
.group[aria-sort='ascending'] .group-aria-\[sort\=ascending\]\:underline,
.peer\/foo[aria-checked='true'] ~ .peer-aria-checked\/foo\:underline,
.peer[aria-checked='true'] ~ .peer-aria-checked\:underline,
.peer[aria-labelledby='a b'] ~ .peer-aria-\[labelledby\=\'a_b\'\]\:underline,
.peer\/foo[aria-sort='ascending'] ~ .peer-aria-\[sort\=ascending\]\/foo\:underline,
.peer[aria-sort='ascending'] ~ .peer-aria-\[sort\=ascending\]\:underline {
text-decoration-line: underline;
}
`)
oxide.expect(result.css).toMatchFormattedCss(css`
.aria-checked\:underline[aria-checked='true'],
.aria-\[labelledby\=\'a_b\'\]\:underline[aria-labelledby='a b'],
.aria-\[sort\=ascending\]\:underline[aria-sort='ascending'],
.group\/foo[aria-checked='true'] .group-aria-checked\/foo\:underline,
.group[aria-checked='true'] .group-aria-checked\:underline,
.group[aria-labelledby='a b'] .group-aria-\[labelledby\=\'a_b\'\]\:underline,
.group\/foo[aria-sort='ascending'] .group-aria-\[sort\=ascending\]\/foo\:underline,
.group[aria-sort='ascending'] .group-aria-\[sort\=ascending\]\:underline,
.peer\/foo[aria-checked='true'] ~ .peer-aria-checked\/foo\:underline,
.peer[aria-checked='true'] ~ .peer-aria-checked\:underline,
.peer[aria-labelledby='a b'] ~ .peer-aria-\[labelledby\=\'a_b\'\]\:underline,
.peer\/foo[aria-sort='ascending'] ~ .peer-aria-\[sort\=ascending\]\/foo\:underline,
.peer[aria-sort='ascending'] ~ .peer-aria-\[sort\=ascending\]\:underline {
text-decoration-line: underline;
}
`)
})
})
it('should support data variants', () => {
let config = {
theme: {
data: {
checked: 'ui~="checked"',
},
},
content: [
{
raw: html`
<div>
<div class="data-checked:underline"></div>
<div class="data-[position=top]:underline"></div>
<div class="data-[foo='bar_baz']:underline"></div>
<div class="group-data-checked:underline"></div>
<div class="peer-data-checked:underline"></div>
<div class="group-data-checked/foo:underline"></div>
<div class="peer-data-checked/foo:underline"></div>
<div class="group-data-[position=top]:underline"></div>
<div class="peer-data-[position=top]:underline"></div>
<div class="group-data-[foo='bar_baz']:underline"></div>
<div class="peer-data-[foo='bar_baz']:underline"></div>
<div class="group-data-[position=top]/foo:underline"></div>
<div class="peer-data-[position=top]/foo:underline"></div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
stable.expect(result.css).toMatchFormattedCss(css`
.underline,
.data-checked\:underline[data-ui~='checked'],
.data-\[foo\=\'bar_baz\'\]\:underline[data-foo='bar baz'],
.data-\[position\=top\]\:underline[data-position='top'],
.group\/foo[data-ui~='checked'] .group-data-checked\/foo\:underline,
.group[data-ui~='checked'] .group-data-checked\:underline,
.group[data-foo='bar baz'] .group-data-\[foo\=\'bar_baz\'\]\:underline,
.group\/foo[data-position='top'] .group-data-\[position\=top\]\/foo\:underline,
.group[data-position='top'] .group-data-\[position\=top\]\:underline,
.peer\/foo[data-ui~='checked'] ~ .peer-data-checked\/foo\:underline,
.peer[data-ui~='checked'] ~ .peer-data-checked\:underline,
.peer[data-foo='bar baz'] ~ .peer-data-\[foo\=\'bar_baz\'\]\:underline,
.peer\/foo[data-position='top'] ~ .peer-data-\[position\=top\]\/foo\:underline,
.peer[data-position='top'] ~ .peer-data-\[position\=top\]\:underline {
text-decoration-line: underline;
}
`)
oxide.expect(result.css).toMatchFormattedCss(css`
.data-checked\:underline[data-ui~='checked'],
.data-\[foo\=\'bar_baz\'\]\:underline[data-foo='bar baz'],
.data-\[position\=top\]\:underline[data-position='top'],
.group\/foo[data-ui~='checked'] .group-data-checked\/foo\:underline,
.group[data-ui~='checked'] .group-data-checked\:underline,
.group[data-foo='bar baz'] .group-data-\[foo\=\'bar_baz\'\]\:underline,
.group\/foo[data-position='top'] .group-data-\[position\=top\]\/foo\:underline,
.group[data-position='top'] .group-data-\[position\=top\]\:underline,
.peer\/foo[data-ui~='checked'] ~ .peer-data-checked\/foo\:underline,
.peer[data-ui~='checked'] ~ .peer-data-checked\:underline,
.peer[data-foo='bar baz'] ~ .peer-data-\[foo\=\'bar_baz\'\]\:underline,
.peer\/foo[data-position='top'] ~ .peer-data-\[position\=top\]\/foo\:underline,
.peer[data-position='top'] ~ .peer-data-\[position\=top\]\:underline {
text-decoration-line: underline;
}
`)
})
})
it('should support supports', () => {
let config = {
theme: {
supports: {
grid: 'display: grid',
},
},
content: [
{
raw: html`
<div>
<!-- Property check -->
<div class="supports-[display:grid]:grid"></div>
<!-- Value with spaces, needs to be normalized -->
<div class="supports-[transform-origin:5%_5%]:underline"></div>
<!-- Selectors (raw) -->
<div class="supports-[selector(A_>_B)]:underline"></div>
<!-- 'not' check (raw) -->
<div class="supports-[not(foo:bar)]:underline"></div>
<!-- 'or' check (raw) -->
<div class="supports-[(foo:bar)or(bar:baz)]:underline"></div>
<!-- 'and' check (raw) -->
<div class="supports-[(foo:bar)and(bar:baz)]:underline"></div>
<!-- No value give for the property, defaulting to prop: var(--tw) -->
<div class="supports-[container-type]:underline"></div>
<!-- Named supports usage -->
<div class="supports-grid:underline"></div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
@supports (display: grid) {
.supports-grid\:underline {
text-decoration-line: underline;
}
.supports-\[display\:grid\]\:grid {
display: grid;
}
}
@supports (foo: bar) and (bar: baz) {
.supports-\[\(foo\:bar\)and\(bar\:baz\)\]\:underline {
text-decoration-line: underline;
}
}
@supports (foo: bar) or (bar: baz) {
.supports-\[\(foo\:bar\)or\(bar\:baz\)\]\:underline {
text-decoration-line: underline;
}
}
@supports (container-type: var(--tw)) {
.supports-\[container-type\]\:underline {
text-decoration-line: underline;
}
}
@supports not (foo: bar) {
.supports-\[not\(foo\:bar\)\]\:underline {
text-decoration-line: underline;
}
}
@supports selector(A > B) {
.supports-\[selector\(A_\>_B\)\]\:underline {
text-decoration-line: underline;
}
}
@supports (transform-origin: 5% 5%) {
.supports-\[transform-origin\:5\%_5\%\]\:underline {
text-decoration-line: underline;
}
}
`)
})
})
test('has-* variants with arbitrary values', () => {
let config = {
theme: {},
content: [
{
raw: html`
<div>
<figure class="has-[figcaption]:inline-block"></figure>
<div class="has-[.foo]:flex"></div>
<div class="has-[.foo:hover]:block"></div>
<div class="has-[[data-active]]:inline"></div>
<div class="has-[>_.potato]:table"></div>
<div class="has-[+_h2]:grid"></div>
<div class="has-[>_h1_+_h2]:contents"></div>
<div class="has-[h2]:has-[.banana]:hidden"></div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.has-\[\.foo\:hover\]\:block:has(.foo:hover) {
display: block;
}
.has-\[figcaption\]\:inline-block:has(figcaption) {
display: inline-block;
}
.has-\[\[data-active\]\]\:inline:has([data-active]) {
display: inline;
}
.has-\[\.foo\]\:flex:has(.foo) {
display: flex;
}
.has-\[\>_\.potato\]\:table:has(> .potato) {
display: table;
}
.has-\[\+_h2\]\:grid:has(+ h2) {
display: grid;
}
.has-\[\>_h1_\+_h2\]\:contents:has(> h1 + h2) {
display: contents;
}
.has-\[h2\]\:has-\[\.banana\]\:hidden:has(.banana):has(h2) {
display: none;
}
`)
})
})
test('group-has-* variants with arbitrary values', () => {
let config = {
theme: {},
content: [
{
raw: html`
<div class="group">
<div class="group-has-[>_h1_+_.foo]:block"></div>
</div>
<div class="group/two">
<div class="group-has-[>_h1_+_.foo]/two:flex"></div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.group:has(> h1 + .foo) .group-has-\[\>_h1_\+_\.foo\]\:block {
display: block;
}
.group\/two:has(> h1 + .foo) .group-has-\[\>_h1_\+_\.foo\]\/two\:flex {
display: flex;
}
`)
})
})
test('peer-has-* variants with arbitrary values', () => {
let config = {
theme: {},
content: [
{
raw: html`
<div>
<div className="peer"></div>
<div class="peer-has-[>_h1_+_.foo]:block"></div>
</div>
<div>
<div className="peer"></div>
<div class="peer-has-[>_h1_+_.foo]/two:flex"></div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.peer:has(> h1 + .foo) ~ .peer-has-\[\>_h1_\+_\.foo\]\:block {
display: block;
}
.peer\/two:has(> h1 + .foo) ~ .peer-has-\[\>_h1_\+_\.foo\]\/two\:flex {
display: flex;
}
`)
})
})
it('should be possible to use modifiers and arbitrary groups', () => {
let config = {
content: [
{
raw: html`
<div>
<div class="group">
<!-- Default group usage -->
<div class="group-hover:underline"></div>
<!-- Arbitrary variants with pseudo class for group -->
<!-- With & -->
<div class="group-[&:focus]:underline"></div>
<!-- Without & -->
<div class="group-[:hover]:underline"></div>
<!-- Arbitrary variants with attributes selectors for group -->
<!-- With & -->
<div class="group-[&[data-open]]:underline"></div>
<!-- Without & -->
<div class="group-[[data-open]]:underline"></div>
<!-- Arbitrary variants with other selectors -->
<!-- With & -->
<div class="group-[.in-foo_&]:underline"></div>
<!-- Without & -->
<div class="group-[.in-foo]:underline"></div>
</div>
<!-- The same as above, but with modifiers -->
<div class="group/foo">
<div class="group-hover/foo:underline"></div>
<div class="group-[&:focus]/foo:underline"></div>
<div class="group-[:hover]/foo:underline"></div>
<div class="group-[&[data-open]]/foo:underline"></div>
<div class="group-[[data-open]]/foo:underline"></div>
<div class="group-[.in-foo_&]/foo:underline"></div>
<div class="group-[.in-foo]/foo:underline"></div>
</div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.group\/foo:hover .group-hover\/foo\:underline,
.group:hover .group-hover\:underline,
.group\/foo:focus .group-\[\&\:focus\]\/foo\:underline,
.group:focus .group-\[\&\:focus\]\:underline,
.group\/foo[data-open] .group-\[\&\[data-open\]\]\/foo\:underline,
.group[data-open] .group-\[\&\[data-open\]\]\:underline,
.group\/foo.in-foo .group-\[\.in-foo\]\/foo\:underline,
.group.in-foo .group-\[\.in-foo\]\:underline,
.in-foo .group\/foo .group-\[\.in-foo_\&\]\/foo\:underline,
.in-foo .group .group-\[\.in-foo_\&\]\:underline,
.group\/foo:hover .group-\[\:hover\]\/foo\:underline,
.group:hover .group-\[\:hover\]\:underline,
.group\/foo[data-open] .group-\[\[data-open\]\]\/foo\:underline,
.group[data-open] .group-\[\[data-open\]\]\:underline {
text-decoration-line: underline;
}
`)
})
})
it('should be possible to use modifiers and arbitrary peers', () => {
let config = {
content: [
{
raw: html`
<div>
<div class="peer"></div>
<!-- Default peer usage -->
<div class="peer-hover:underline"></div>
<!-- Arbitrary variants with pseudo class for peer -->
<!-- With & -->
<div class="peer-[&:focus]:underline"></div>
<!-- Without & -->
<div class="peer-[:hover]:underline"></div>
<!-- Arbitrary variants with attributes selectors for peer -->
<!-- With & -->
<div class="peer-[&[data-open]]:underline"></div>
<!-- Without & -->
<div class="peer-[[data-open]]:underline"></div>
<!-- Arbitrary variants with other selectors -->
<!-- With & -->
<div class="peer-[.in-foo_&]:underline"></div>
<!-- Without & -->
<div class="peer-[.in-foo]:underline"></div>
<!-- The same as above, but with modifiers -->
<div class="peer/foo"></div>
<div class="peer-hover/foo:underline"></div>
<div class="peer-[&:focus]/foo:underline"></div>
<div class="peer-[:hover]/foo:underline"></div>
<div class="peer-[&[data-open]]/foo:underline"></div>
<div class="peer-[[data-open]]/foo:underline"></div>
<div class="peer-[.in-foo_&]/foo:underline"></div>
<div class="peer-[.in-foo]/foo:underline"></div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.peer\/foo:hover ~ .peer-hover\/foo\:underline,
.peer:hover ~ .peer-hover\:underline,
.peer\/foo:focus ~ .peer-\[\&\:focus\]\/foo\:underline,
.peer:focus ~ .peer-\[\&\:focus\]\:underline,
.peer\/foo[data-open] ~ .peer-\[\&\[data-open\]\]\/foo\:underline,
.peer[data-open] ~ .peer-\[\&\[data-open\]\]\:underline,
.peer\/foo.in-foo ~ .peer-\[\.in-foo\]\/foo\:underline,
.peer.in-foo ~ .peer-\[\.in-foo\]\:underline,
.in-foo .peer\/foo ~ .peer-\[\.in-foo_\&\]\/foo\:underline,
.in-foo .peer ~ .peer-\[\.in-foo_\&\]\:underline,
.peer\/foo:hover ~ .peer-\[\:hover\]\/foo\:underline,
.peer:hover ~ .peer-\[\:hover\]\:underline,
.peer\/foo[data-open] ~ .peer-\[\[data-open\]\]\/foo\:underline,
.peer[data-open] ~ .peer-\[\[data-open\]\]\:underline {
text-decoration-line: underline;
}
`)
})
})
it('Arbitrary variants are ordered alphabetically', () => {
let config = {
content: [
{
raw: html`
<div>
<div class="[&::b]:underline"></div>
<div class="[&::a]:underline"></div>
<div class="[&::c]:underline"></div>
<div class="[&::b]:underline"></div>
</div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.\[\&\:\:a\]\:underline::a {
text-decoration-line: underline;
}
.\[\&\:\:b\]\:underline::b {
text-decoration-line: underline;
}
.\[\&\:\:c\]\:underline::c {
text-decoration-line: underline;
}
`)
})
})
it('Arbitrary variants support multiple attribute selectors', () => {
let config = {
content: [
{
raw: html` <div class="[[data-foo='bar'][data-baz]_&]:underline"></div> `,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
[data-foo='bar'][data-baz] .\[\[data-foo\=\'bar\'\]\[data-baz\]_\&\]\:underline {
text-decoration-line: underline;
}
`)
})
})
it('Invalid arbitrary variants selectors should produce nothing instead of failing', () => {
let config = {
content: [
{
raw: html`
<div class="[&;foo]:underline"></div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css``)
})
})
it('should output responsive variants + stacked variants in the right order', () => {
let config = {
content: [
{
raw: html`
<div class="xl:p-1"></div>
<div class="md:[&_ul]:flex-row"></div>
<div class="[&_ul]:flex"></div>
<div class="[&_ul]:flex-col"></div>
`,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
@media (min-width: 1280px) {
.xl\:p-1 {
padding: 0.25rem;
}
}
.\[\&_ul\]\:flex ul {
display: flex;
}
.\[\&_ul\]\:flex-col ul {
flex-direction: column;
}
@media (min-width: 768px) {
.md\:\[\&_ul\]\:flex-row ul {
flex-direction: row;
}
}
`)
})
})
it('it should discard arbitrary variants with multiple selectors', () => {
let config = {
content: [
{
raw: html`
<div class="p-1"></div>
<div class="[div]:p-1"></div>
<div class="[div_&]:p-1"></div>
<div class="[div,span]:p-1"></div>
<div class="[div_&,span]:p-1"></div>
<div class="[div,span_&]:p-1"></div>
<div class="[div_&,span_&]:p-1"></div>
<div class="hover:[div]:p-1"></div>
<div class="hover:[div_&]:p-1"></div>
<div class="hover:[div,span]:p-1"></div>
<div class="hover:[div_&,span]:p-1"></div>
<div class="hover:[div,span_&]:p-1"></div>
<div class="hover:[div_&,span_&]:p-1"></div>
<div class="hover:[:is(span,div)_&]:p-1"></div>
`,
},
{
// escaped commas are a-ok
// This is separate because prettier complains about `\,` in the template string
raw: '<div class="hover:[.span\\,div_&]:p-1"></div>',
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.p-1,
.span\,div .hover\:\[\.span\\\,div_\&\]\:p-1:hover,
:is(span, div) .hover\:\[\:is\(span\,div\)_\&\]\:p-1:hover,
div .\[div_\&\]\:p-1,
div .hover\:\[div_\&\]\:p-1:hover {
padding: 0.25rem;
}
`)
})
})
it('should sort multiple variant fns with normal variants between them', () => {
/** @type {string[]} */
let lines = []
for (let a of [1, 2]) {
for (let b of [2, 1]) {
for (let c of [1, 2]) {
for (let d of [2, 1]) {
for (let e of [1, 2]) {
lines.push(`<div class="fred${a}:qux-[${b}]:baz${c}:bar-[${d}]:foo${e}:p-1"></div>`)
}
}
}
}
}
// Fisher-Yates shuffle
for (let i = lines.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * i)
;[lines[i], lines[j]] = [lines[j], lines[i]]
}
let config = {
content: [
{
raw: lines.join('\n'),
},
],
corePlugins: { preflight: false },
plugins: [
function ({ addVariant, matchVariant }) {
addVariant('foo1', "&[data-foo='1']")
addVariant('foo2', "&[data-foo='2']")
matchVariant('bar', (value) => `&[data-bar='${value}']`, {
sort: (a, b) => b.value - a.value,
})
addVariant('baz1', "&[data-baz='1']")
addVariant('baz2', "&[data-baz='2']")
matchVariant('qux', (value) => `&[data-qux='${value}']`, {
sort: (a, b) => b.value - a.value,
})
addVariant('fred1', "&[data-fred='1']")
addVariant('fred2', "&[data-fred='2']")
},
],
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.fred1\:qux-\[2\]\:baz1\:bar-\[2\]\:foo1\:p-1[data-foo='1'][data-bar='2'][data-baz='1'][data-qux='2'][data-fred='1'],
.fred1\:qux-\[2\]\:baz1\:bar-\[2\]\:foo2\:p-1[data-foo='2'][data-bar='2'][data-baz='1'][data-qux='2'][data-fred='1'],
.fred1\:qux-\[2\]\:baz1\:bar-\[1\]\:foo1\:p-1[data-foo='1'][data-bar='1'][data-baz='1'][data-qux='2'][data-fred='1'],
.fred1\:qux-\[2\]\:baz1\:bar-\[1\]\:foo2\:p-1[data-foo='2'][data-bar='1'][data-baz='1'][data-qux='2'][data-fred='1'],
.fred1\:qux-\[2\]\:baz2\:bar-\[2\]\:foo1\:p-1[data-foo='1'][data-bar='2'][data-baz='2'][data-qux='2'][data-fred='1'],
.fred1\:qux-\[2\]\:baz2\:bar-\[2\]\:foo2\:p-1[data-foo='2'][data-bar='2'][data-baz='2'][data-qux='2'][data-fred='1'],
.fred1\:qux-\[2\]\:baz2\:bar-\[1\]\:foo1\:p-1[data-foo='1'][data-bar='1'][data-baz='2'][data-qux='2'][data-fred='1'],
.fred1\:qux-\[2\]\:baz2\:bar-\[1\]\:foo2\:p-1[data-foo='2'][data-bar='1'][data-baz='2'][data-qux='2'][data-fred='1'],
.fred1\:qux-\[1\]\:baz1\:bar-\[2\]\:foo1\:p-1[data-foo='1'][data-bar='2'][data-baz='1'][data-qux='1'][data-fred='1'],
.fred1\:qux-\[1\]\:baz1\:bar-\[2\]\:foo2\:p-1[data-foo='2'][data-bar='2'][data-baz='1'][data-qux='1'][data-fred='1'],
.fred1\:qux-\[1\]\:baz1\:bar-\[1\]\:foo1\:p-1[data-foo='1'][data-bar='1'][data-baz='1'][data-qux='1'][data-fred='1'],
.fred1\:qux-\[1\]\:baz1\:bar-\[1\]\:foo2\:p-1[data-foo='2'][data-bar='1'][data-baz='1'][data-qux='1'][data-fred='1'],
.fred1\:qux-\[1\]\:baz2\:bar-\[2\]\:foo1\:p-1[data-foo='1'][data-bar='2'][data-baz='2'][data-qux='1'][data-fred='1'],
.fred1\:qux-\[1\]\:baz2\:bar-\[2\]\:foo2\:p-1[data-foo='2'][data-bar='2'][data-baz='2'][data-qux='1'][data-fred='1'],
.fred1\:qux-\[1\]\:baz2\:bar-\[1\]\:foo1\:p-1[data-foo='1'][data-bar='1'][data-baz='2'][data-qux='1'][data-fred='1'],
.fred1\:qux-\[1\]\:baz2\:bar-\[1\]\:foo2\:p-1[data-foo='2'][data-bar='1'][data-baz='2'][data-qux='1'][data-fred='1'],
.fred2\:qux-\[2\]\:baz1\:bar-\[2\]\:foo1\:p-1[data-foo='1'][data-bar='2'][data-baz='1'][data-qux='2'][data-fred='2'],
.fred2\:qux-\[2\]\:baz1\:bar-\[2\]\:foo2\:p-1[data-foo='2'][data-bar='2'][data-baz='1'][data-qux='2'][data-fred='2'],
.fred2\:qux-\[2\]\:baz1\:bar-\[1\]\:foo1\:p-1[data-foo='1'][data-bar='1'][data-baz='1'][data-qux='2'][data-fred='2'],
.fred2\:qux-\[2\]\:baz1\:bar-\[1\]\:foo2\:p-1[data-foo='2'][data-bar='1'][data-baz='1'][data-qux='2'][data-fred='2'],
.fred2\:qux-\[2\]\:baz2\:bar-\[2\]\:foo1\:p-1[data-foo='1'][data-bar='2'][data-baz='2'][data-qux='2'][data-fred='2'],
.fred2\:qux-\[2\]\:baz2\:bar-\[2\]\:foo2\:p-1[data-foo='2'][data-bar='2'][data-baz='2'][data-qux='2'][data-fred='2'],
.fred2\:qux-\[2\]\:baz2\:bar-\[1\]\:foo1\:p-1[data-foo='1'][data-bar='1'][data-baz='2'][data-qux='2'][data-fred='2'],
.fred2\:qux-\[2\]\:baz2\:bar-\[1\]\:foo2\:p-1[data-foo='2'][data-bar='1'][data-baz='2'][data-qux='2'][data-fred='2'],
.fred2\:qux-\[1\]\:baz1\:bar-\[2\]\:foo1\:p-1[data-foo='1'][data-bar='2'][data-baz='1'][data-qux='1'][data-fred='2'],
.fred2\:qux-\[1\]\:baz1\:bar-\[2\]\:foo2\:p-1[data-foo='2'][data-bar='2'][data-baz='1'][data-qux='1'][data-fred='2'],
.fred2\:qux-\[1\]\:baz1\:bar-\[1\]\:foo1\:p-1[data-foo='1'][data-bar='1'][data-baz='1'][data-qux='1'][data-fred='2'],
.fred2\:qux-\[1\]\:baz1\:bar-\[1\]\:foo2\:p-1[data-foo='2'][data-bar='1'][data-baz='1'][data-qux='1'][data-fred='2'],
.fred2\:qux-\[1\]\:baz2\:bar-\[2\]\:foo1\:p-1[data-foo='1'][data-bar='2'][data-baz='2'][data-qux='1'][data-fred='2'],
.fred2\:qux-\[1\]\:baz2\:bar-\[2\]\:foo2\:p-1[data-foo='2'][data-bar='2'][data-baz='2'][data-qux='1'][data-fred='2'],
.fred2\:qux-\[1\]\:baz2\:bar-\[1\]\:foo1\:p-1[data-foo='1'][data-bar='1'][data-baz='2'][data-qux='1'][data-fred='2'],
.fred2\:qux-\[1\]\:baz2\:bar-\[1\]\:foo2\:p-1[data-foo='2'][data-bar='1'][data-baz='2'][data-qux='1'][data-fred='2'] {
padding: 0.25rem;
}
`)
})
})
})