Discard invalid classes such as bg-red-[#000]#13970
Merged
Merged
Conversation
When using arbitrary values such as `bg-[#0088cc]` then we know that everything before the `-[` part is the `root` of the utility. This also means that this should exist in the design system as-is. If we use `findRoot` instead, it means that `bg-red-[#0088cc]` would also just parse fine and we don't want.
It's not necessary to track state in a state object. Let's use the variables directly.
The value doesn't change anymore, which means we can discard early and don't need to start creating candidate objects.
bg-red-[#000]
bg-red-[#000]bg-red-[#000]
thecrypticace
approved these changes
Jul 9, 2024
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves the candidate parser by making sure that invalid candidates are discarded earlier.
When using a utility such as
bg-red-500, then we have to find the actual plugin by finding theroot. In this case we will try:bg-red-500, value: null <- No match yetbg-red, value:500<- No match yetbg, value:red-500<- Bingo,bgis a known rootHowever, if you are using arbitrary values such as
bg-[#000], then we know that everything before the-[#000]will be the root of the plugin. In this case we can do a direct lookup forbg.Before this change, this wasn't the case (in v4), which means that we could write
bg-red-[#000]and it parsed just fine.This PR also adds a test for a case that wasn't covered by any tests, which is when you use a candidate such as
bg-. This parsed as a root of"bg"and a value of"".