-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Upgrade: Ensure underscores in url() and var() are not escaped #14778
Upgrade: Ensure underscores in url() and var() are not escaped #14778
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @philipp-spiess and the rest of your teammates on Graphite |
48526c7
to
55720f2
Compare
6460bcb
to
21eb011
Compare
55720f2
to
1b75b2b
Compare
21eb011
to
75aa966
Compare
1b75b2b
to
12b61ca
Compare
12b61ca
to
9adc483
Compare
function never(): never { | ||
throw new Error('This should never happen') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to inline this if it's only ever called once? Also wonder if it would be helpful to use a more descriptive message like "Unexpected node kind `${node.kind}` is not handled for when escaping underscores" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here is to use the never
type so that TypeScript can actually notify us when we add a test (creating an exhaustive switch)
But... I did screw this up, we actually need to assert that node.value
has the type never
not just the return function here. 😶🌫️
This way that symbol is never read, it won't even compile if a new type to the ValueParser is added!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another fun solution to this problem is to use
default:
node satisfies never
Then you don't get a runtime error, but only a compile time one. But I think in either solution (current one and the one I'm showing) we always build regardless of build errors (or at least, it seems to be building locally) 🤔.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I tried with as
and it wasn't working, didn't test satisfies! Yeah might be cleaner.
On the other thing: I think it's fine if it actually builds but at least CI should yell at us if we have a type issue somewhere.
9adc483
to
0999612
Compare
Co-authored-by: Adam Wathan <[email protected]>
This PR fixes an issue where currently a
theme()
function call inside an arbitrary value that used a dot in the key path:Was causing issues when going though the codemod. The issue is that for candidates, we require
_
to be escaped, since otherwise they will be replaced with underscore. When going through the codemods, the above candidate would be translated to the following CSS variable access:Because the underscore was escaped, we now have an invalid string inside a JavaScript file (as the
\
would escape inside the quoted string.To resolve this, we decided that this common case (as its used by the Tailwind CSS default theme) should work without escaping. In #14776, we made the changes that CSS variables used via
var()
no longer unescape underscores. This PR extends that so that the Variant printer (that creates the serialized candidate representation after the codemods make changes) take this new encoding into account.This will result in the above example being translated into:
With no more escaping. Nice!
Test Plan
I have added test for this to the kitchen-sink upgrade tests. Furthermore, to ensure this really works full-stack, I have updated the kitchen-sink test to actually build the migrated project with Tailwind CSS v4. After doing so, we can assert that we indeed have the right class name in the generated CSS.