-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Show warning when using unsupported bare value data type #17464
Show warning when using unsupported bare value data type #17464
Conversation
!BARE_VALUE_DATA_TYPES.includes(node.value) | ||
) { | ||
console.warn( | ||
`Unsupported bare value data type: "${node.value}".\nOnly valid data types are: ${BARE_VALUE_DATA_TYPES.map((x) => `"${x}"`).join(', ')}\n`, |
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.
@adamwathan do you want to make any changes to this warning?
Output looks something like this right now:
Unsupported bare value data type: "color".
Only valid data types are: "number", "integer", "ratio", "percentage"
```css
--value([color],color)
^^^^^
```
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.
My 5 ct: I don't think the term "bare value" is something that people of that API will be familiar with but maybe we just call it "value data type" (since it's the --value(…)
function)?
Unsupported value data type: "color".
Only valid data types are: "number", "integer", "ratio", "percentage".
```css
--value([color],color)
^^^^^
```
The rest I think is fine personally but I'd add a dot at the end of the second sentence
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.
I think people writing plugins like that will be more familiar with the term (or at least should be because they will have to know the difference between color
and [color]
).
Main reason I used it is because that's what we use in the docs for it: https://tailwindcss.com/docs/adding-custom-styles#bare-values
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.
Ohh right we do refer to it like that in the docs huh, yep then I think this does make sense
33c8609
to
3fef1e4
Compare
This PR will show a warning if you are using a bare value data type that is not supported.
Let's say you want to create a new utility that allows
color
to be a bare value data type like this:This means that this would enable new syntax that we don't support yet. E.g.:
paint-#0088cc
.The only supported data types for bare values are:
number
—2.5
integer
—2
ratio
—1/2
percentage
—50%
All other data types are not supported in this position. This PR will now show a warning:
Once we have better sourcemap / location tracking support, this warning will point to the exact spot, but for now, only a re-print of the AST can be used.
If you do want to use other data types, then you will have to use arbitrary value syntax with
[…]
instead.This will allow for
paint-[#0088cc]
for example.Note: this is not a behavioral change, we already didn't support other data types, but we silently ignored them. This means that we have to do more parsing at runtime when evaluating the utility.
With this change, a warning is shown when registering the
@utility
, not when using it.