tailwindcss/packages/@tailwindcss-upgrade/src/codemods
Philipp Spiess ca7b10e7d3
Make --theme(…) return CSS variables (#17036)
Closes #16945

This PR changes the `--theme(…)` function now return CSS `var(…)`
definitions unless used in places where `var(…)` is not valid CSS (e.g.
in `@media (width >= theme(--breakpoint-md))`):

```css
/* input */
@theme {
  --color-red: red;
}
.red {
  color: --theme(--color-red);
}

/* output */
:root, :host {
  --color-red: red;
}
.red {
  color: var(--color-red);
}
```

Furthermore, this adds an `--theme(… inline)` option to the `--theme(…)`
function to force the resolution to be inline, e.g.:

```css
/* input */
@theme {
  --color-red: red;
}
.red {
  color: --theme(--color-red inline);
}

/* output */
.red {
  color: red;
}
```

This PR also changes preflight and the default theme to use this new
`--theme(…)` function to ensure variables are prefixed correctly.

## Test plan

- Added unit tests and a test that pulls in the whole preflight under a
prefix theme.
2025-03-20 12:51:22 +01:00
..
fixtures Upgrade: Rewrite imports of relative files to use relative file paths (#14755) 2024-10-22 16:30:41 -04:00
format-nodes.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
format-nodes.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-at-apply.test.ts Ensure clients pin the tailwindcss version (#15011) 2024-11-15 17:18:48 +01:00
migrate-at-apply.ts Ensure clients pin the tailwindcss version (#15011) 2024-11-15 17:18:48 +01:00
migrate-at-layer-utilities.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-at-layer-utilities.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-config.ts Ensure @config is injected in common ancestor sheet (#14989) 2024-11-14 11:48:31 +01:00
migrate-import.test.ts Upgrade: don't show error during upgrade when analyzing external URL import (#15040) 2024-11-19 15:52:30 +01:00
migrate-import.ts Upgrade: don't show error during upgrade when analyzing external URL import (#15040) 2024-11-19 15:52:30 +01:00
migrate-media-screen.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-media-screen.ts Make --theme(…) return CSS variables (#17036) 2025-03-20 12:51:22 +01:00
migrate-missing-layers.test.ts Always add layer(…) as the first param to @import (#15102) 2024-11-22 14:09:26 +00:00
migrate-missing-layers.ts Implement @variant (#15663) 2025-01-21 10:20:35 -05:00
migrate-preflight.test.ts Implement @variant (#15663) 2025-01-21 10:20:35 -05:00
migrate-preflight.ts Revert new default form styles (#15100) 2024-11-22 08:55:05 -05:00
migrate-tailwind-directives.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-tailwind-directives.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00
migrate-theme-to-var.test.ts Migrate theme(…) to --theme(…), migrate calc(var(--spacing)*x) to --spacing(x) (#15579) 2025-01-09 17:17:07 +01:00
migrate-theme-to-var.ts Migrate theme(…) to var(…) in CSS (#14695) 2024-10-17 11:50:27 +02:00
migrate-variants-directive.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-variants-directive.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00
sort-buckets.ts Implement @variant (#15663) 2025-01-21 10:20:35 -05:00