Skip to content

Commit c956b08

Browse files
committed
big refactor
Note: we made sure that all the tests passed before this commit, and we also made sure to not touch any of the tests as part of this commit ensuring that everything still works as expected. Aka, an actual refactor without behavior change. This is a big commit and a big refactor but that's mainly because there are some re-indents that are happening. Will maybe split up this commit but then it won't be an atomic (working) commit anymore. One thing I noticed is that all our "migrations" essentially parsed a raw candidate, did some work and then stringified the candidate AST again. That's one of the reasons I inlined the migrations in previous commits in a single file. Looking at the file now, it's a little bit silly that we parse and print over and over again. Parsing a raw candidate also results in an an array of `Candidate` AST nodes, so we always had a loop going on. Another thing I noticed is that often we need to work with a "base" candidate, that's essentially the candidate without the variants and without the important flag. That's where this refactor comes in: 1. We parse each candidate _once_ 2. When there are variants, we canonicalize each variant separately and store the results in a separate cache. 3. When there are variants _or_ the important flag is present, we canonicalize the base utility separately and later re-attach the variants and important flag at the end. This means that not a single canonicalization step has to deal with variants or important flag. 4. Since we only want to parse the candidate once on the outside, we will pass a cloned `Candidate` to each canonicalize step to prevent parsing and printing over and over again. 5. Only at the end will we re-print the `Candidate` This process has a few benefits: 1. We are handling candidates and variants separately and caching them separately. This means that we can increase cache hits because variants from candidate A and candidate B can be re-used. E.g.: `[@media_print]:flex` and `[@media_print]:underline` will map to `print:flex` and `print:underline` where `[@media_print]` is only handled once. 2. This also means that we could simplify some canonicalization steps because they don't have to worry about variants and the important flag. 3. There is no parsing & looping over the parsed candidates array going on.
1 parent 02ba94f commit c956b08

File tree

1 file changed

+658
-710
lines changed

1 file changed

+658
-710
lines changed

0 commit comments

Comments
 (0)