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
refactor(preset-attributify): improve ternary extraction #1921
refactor(preset-attributify): improve ternary extraction #1921
Conversation
✅ Deploy Preview for unocss ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
@sibbng Can you check your pr with this playground |
In #1915 , I am more inclined that this is a user's usage rules problem. |
posTest is not a valid rule. So it's not picked up by any attributify selector.
No, it's not. We already have a test for extracting ternaries from vue templates. This PR adds support for JSX. |
test/preset-attributify.test.ts:22 |
unocss/test/preset-attributify.test.ts Line 22 in 22c4e70
About this line, you can see UnoCSS extracted results: unocss/test/__snapshots__/preset-attributify.test.ts.snap Lines 28 to 34 in 22c4e70
Only font-mono and font-sans can be parsed, because we have its rules.unocss/test/__snapshots__/preset-attributify.test.ts.snap Lines 199 to 200 in 22c4e70
In #1915, We don't have any rule or variant about |
unocss/packages/preset-mini/src/_rules/position.ts Lines 5 to 9 in 22c4e70
This is exactly what I called false positives. In this case, they will not make into output since there are no matching rules as you said. But, what if the variables we used in ternaries are has matching rules? e.g: <div
:text="xl ? '5xl' : 'base'"
/> As you can see from the output an unnecessary selector This PR makes sure, only the quoted strings in the true or false side of the ternary are extracted. Both for vue and JSX. |
I'm so sorry, and thanks for you answer, you are right. I never use |
Thanks for this PR, are there any plans for new releases in the near future? |
Fixes #1915
It seems we already support this in Vue templates. This PR adds support for ternary operators in JSX and eliminates some false positives of previous ternary extraction logic.