-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit d8a0660
improve algorithm
A bit of a vague commit message, but this does a lot of things. I could
split it up, but not sure if it's worth it. Instead, let's talk about
it.
While working on keeping track of comment locations I was running into
some issues. Not the end of the world, but we could make things better.
Paired with Jordan on this to rework the algorithm. The idea is that we
now do multiple passes which is technically slower, but now we can work
on separate units of work.
- Step #1 is to prepare the at-rule. This means that rules with multiple
selectors will be split in multiple nodes with the their own single
selector.
- Step #2 is to collect all the classes we want to create an `@utility`
for.
- Step #3 is to create a clone of the main `@layer utilities` for all
the non-`@utility` leftover nodes (E.g.: rules with element and ID
selectors).
- Step #4 is to create a clone of the main `@layer utilities` node for
every single `@utility <name>` we want to create.
- Step #5 is to go over every clone, and eliminate everything that is
not part of the `@utility` in question. So we can remove siblings
(except for comments near it) and go up the chain.
- Step #6 is now to go over the initial `@layer utilities` clone we set
aside, and remove everything that's not part of any of the clones.
- Step #7 is cleanup work, where empty nodes are removed, and rules with
a selector of `&` are replaced by its children. This is done in a
depth-first traversal instead of breadth first.
Co-authored-by: Jordan Pittman <jordan@cryptica.me>1 parent 024ee9d commit d8a0660Copy full SHA for d8a0660
File tree
Expand file treeCollapse file tree
2 files changed
+569
-203
lines changedOpen diff view settings
Filter options
- packages/@tailwindcss-upgrade/src/codemods
Expand file treeCollapse file tree
2 files changed
+569
-203
lines changedOpen diff view settings
0 commit comments