tailwindcss/packages
Philipp Spiess 60e61950b9
Ensure escaped theme variables are handled correctly (#16064)
This PR ensures that escaped theme variables are properly handled. We do
this by moving the `escape`/`unescape` responsibility back into the main
tailwindcss entrypoint that reads and writes from the CSS and making
sure that _all internal state of the `Theme` class are unescaped
classes.

However, due to us accidentally shipping the part where a dot in the
theme variable would translate to an underscore in CSS already, this
logic is going to stay as-is for now.

Here's an example test that visualizes the new changes:

```ts
expect(
  await compileCss(
    css`
      @theme {
        --spacing-*: initial;
        --spacing-1\.5: 2.5rem;
        --spacing-foo\/bar: 3rem;
      }
      @tailwind utilities;
    `,
    ['m-1.5', 'm-foo/bar'],
  ),
).toMatchInlineSnapshot(`
  ":root, :host {
    --spacing-1\.5: 2.5rem;
    --spacing-foo\\/bar: 3rem;
  }

  .m-1\\.5 {
    margin: var(--spacing-1\.5);
  }

  .m-foo\\/bar {
    margin: var(--spacing-foo\\/bar);
  }"
`)
```

## Test plan

- Added a unit test
- Ensure this works end-to-end using the Vite playground:
   
<img width="1016" alt="Screenshot 2025-01-30 at 14 51 05"
src="https://github.com/user-attachments/assets/463c6fd5-793f-4ecc-86d2-5ad40bbb3e74"
/>
2025-01-31 15:20:18 +01:00
..
@tailwindcss-browser Prepare v4.0.1 release (#16018) 2025-01-29 14:14:35 -05:00
@tailwindcss-cli Prepare v4.0.1 release (#16018) 2025-01-29 14:14:35 -05:00
@tailwindcss-node Prepare v4.0.1 release (#16018) 2025-01-29 14:14:35 -05:00
@tailwindcss-postcss Ensure we process Tailwind CSS features when using @reference (#16057) 2025-01-30 15:29:08 +00:00
@tailwindcss-standalone Prepare v4.0.1 release (#16018) 2025-01-29 14:14:35 -05:00
@tailwindcss-upgrade Prepare v4.0.1 release (#16018) 2025-01-29 14:14:35 -05:00
@tailwindcss-vite Fix Vite issues with SolidStart (#16052) 2025-01-30 16:58:20 +01:00
internal-example-plugin Prefix internal modules with internal-* (#14074) 2024-07-29 10:58:07 -04:00
tailwindcss Ensure escaped theme variables are handled correctly (#16064) 2025-01-31 15:20:18 +01:00
tsconfig.base.json Improve debug logs (#15303) 2024-12-11 15:27:20 +01:00