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

Improve support for CustomFunction transforms #485

Closed
wants to merge 7 commits into from

Conversation

phoenix-ru
Copy link
Contributor

@phoenix-ru phoenix-ru commented May 7, 2023

This PR enables authoring custom transformers for PseudoElement and PseudoClass CustomFunctions.

Parsing whitespace inside custom pseudo functions is now more conservative

Previously, :foo(.bar .baz .qux) was parsed as :foo(.bar.baz.qux) which greatly limited custom transformers.

This PR bypasses aggressive whitespace removal inside TokenList::parse_into behind a flag.

To ensure that no API change is introduced, conservative parsing is only enabled for CustomFunction via new TokenList::parse_preserve_whitespace.

Selector manipulations got two more public methods

Selector::append is a useful method for adding extra components to selectors, however it is quite limited when adding Component::Combinator and makes it impossible to reliably append complex expressions like .foo > .bar #baz

  • Selector::insert_raw(&mut self, index: usize, component: Component) can be used for inserting new selector components into an arbitrary location, bypassing the limitations of append;
  • Selector::insert_raw_multiple(&mut self, index: usize, mut components: Vec<Component>) is an optimized version of insert_raw to avoid the extra cost of allocations and memcpy when making multiple calls.

Tests

Tests were added to ensure the correctness of a different parsing strategy. No existing tests changed

@phoenix-ru
Copy link
Contributor Author

Based on the current Pull Request, I implemented Vue's scoped style transforms using lightningcss

https://github.com/phoenix-ru/rust-vue-compiler/blob/8c97a06289695bf6fec146431c882d1b175b263d/crates/fervid_css/src/lib.rs#L53-L147

@devongovett
Copy link
Member

I think this commit should cover this usecase as well: 6a2adb6. That will preserve all tokens inside pseudo selector functions unmodified.

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

2 participants