Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Don't add spaces to gradients and grid track names when followed by calc() #12704

Merged
merged 3 commits into from
Jan 3, 2024

Conversation

thecrypticace
Copy link
Contributor

We do spacing normalization around operators so you can write things like w-[calc(100%-2px)] and not have to worry about inserting spaces. We use a combination of regex and a mini lexer for this but the regexes are prone to over matching.

This PR adds a targeted fix that prevents us from inserting spaces for the following CSS functions:

  • radial-gradient
  • linear-gradient
  • conic-gradient
  • repeating-radial-gradient
  • repeating-linear-gradient
  • repeating-conic-gradient

Additionally, I've added a fix that prevents the addition of spaces around - when inside a CSS grid track name that's encased in square brackets.

Before:

.bg-\[radial-gradient\(calc\(\)\)\2c radial-gradient\(calc\(\)\)\]{
  background-image: radial-gradient(calc()),radial - gradient(calc())
}

.grid-cols-\[\[content-start\]_calc\(100\%-1px\)_\[content-end\]_calc\(1rem\+1px\)\]{
  grid-template-columns: [content-start] calc(100% - 1px) [content - end] calc(1rem + 1px)
}

After:

.bg-\[radial-gradient\(calc\(\)\)\2c radial-gradient\(calc\(\)\)\]{
  background-image: radial-gradient(calc()),radial-gradient(calc())
}

.grid-cols-\[\[content-start\]_calc\(100\%-1px\)_\[content-end\]_calc\(1rem\+1px\)\]{
  grid-template-columns: [content-start] calc(100% - 1px) [content-end] calc(1rem + 1px)
}

An even better solution would be to eventually introduce a lexer that's more top-level and understands CSS function syntax but that will have to happen another day.

Fixes #12654
Fixes #12665

@thecrypticace thecrypticace merged commit 47107be into master Jan 3, 2024
10 checks passed
@thecrypticace thecrypticace deleted the fix/operating-spacing-normalization branch January 3, 2024 18:03
thecrypticace added a commit that referenced this pull request Jan 3, 2024
…calc()` (#12704)

* Don’t break gradient functions when following `calc()`

* Don’t break CSS grid track names

* Update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant