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

feat(presets): configurable separator #1791

Merged
merged 1 commit into from Jan 25, 2023
Merged

Conversation

chu121su12
Copy link
Collaborator

@chu121su12 chu121su12 commented Oct 23, 2022

This PR adds configurable separator to the three built-in presets.

Reference: #1573, #1704

Edit: rebase commit

@netlify
Copy link

netlify bot commented Oct 23, 2022

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit af1bcb7
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/63bb9f96aeb7dd0008722b77
😎 Deploy Preview https://deploy-preview-1791--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@antfu
Copy link
Member

antfu commented Oct 25, 2022

I am not sure if the complexity is it worth here. And I didn't find a strong reason why the separator needs to be configurable. Anyone share more context?

@chu121su12 chu121su12 changed the title feat(presets)!: configurable separator feat(presets): configurable separator Oct 25, 2022
@chu121su12
Copy link
Collaborator Author

@tjk please excuse me for the ping. I'd like to ask for your take

@tjk
Copy link
Contributor

tjk commented Oct 25, 2022

I personally think it's very highly worth it since tailwind allows configuring separator and if someone uses _ (like we do) then trying to transition to preset-wind, etc. without this functionality is impossible without some internal hack. The regexes get memoized and I don't find this highly complex anyway but obviously @antfu need to change his feeling for this to get merged...

Maybe you can tell us what you think the suggestion is for someone trying to migrate a large codebase with a custom separator then if you don't want this merged?


Maybe somehow memoizing the entire substring (?:${ctx.config.separators.join("|")) would reduce some complexity -- eg. ctx.reSep?

@antfu
Copy link
Member

antfu commented Oct 26, 2022

This PR changes quite a lot of static regex into dynamic ones. Static regex is one of the key reasons UnoCSS is fast, as the JS engine could do JIT optimization and compile them to native code. While on the other hand, creating regex in every pass breaks that and would decrease the performance quite a bit.

For your need, it's actually quite simple to do with a one-line variant:
https://uno.antfu.me/play/?html=DwEwlgbgBAxgNgQwM5ILwCIAuBTAHpgfQCdsR0A%2BAJQFEARYAenAnKA&config=JYWwDg9gTgLgBAbwFBzgEwKYDNgDsMDCEuOA5gDQpxhQYDOGMAgjDFMAEYCuMwWAnpVQ16jAJIBjYnSHVaDGAFVcESgF84WKBBBwA5FxUS6dPUiQYAHpFjpsAQy4AbeJhz4iJYKQAUyVABu9uz2uDB0AFxwANpUqD4MThgSMNAAlHAAvAB8cInJqVAAdLRgTvYSGD4A9AD61RT6ALR6aVQAurIiCpExcXKiSio%2BabLC8owsbJw8fPwjsu1Iam1AA&options=N4XyA

export default defineConfig({
  variants: [
    (selector) => selector.replace(/_/g, '-')
  ],
  presets: [
    presetUno(),
    presetAttributify(),
  ]
})

@chu121su12
Copy link
Collaborator Author

I've updated the regexes that can be cached; otherwise, the variant approach is acceptable too

@chu121su12 chu121su12 marked this pull request as ready for review January 9, 2023 05:14
Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Let's ship it in the next minor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants