-
Notifications
You must be signed in to change notification settings - Fork 464
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
[WIP] Prepare selector refactoring for extend refactoring #2904
Conversation
@nex3 from an implementer standpoint I would really like to have more low-level spec-tests.
I know those functions are probably useless for end-users, but AFAICS their APIs seem Just wanted to ask if that would be something you might consider or not? Thanks! Btw. here my local code for
BuiltInCallable("selector-trim", r"$selectors", (arguments) {
var selectors = arguments[0].assertSelector(name: "selectors");
var result = Extender.trim(selectors.components);
return SelectorList(result).asSassList;
})
static List<ComplexSelector> trim(List<ComplexSelector> selectors) {
var extender = Extender._mode(ExtendMode.normal);
return extender._trim(selectors, extender._originals.contains);
} |
I'm not a big fan of adding this to the language, for a couple reasons. First, as you say, it's not very useful for end-users and I want to keep the set of functions we expose pretty tightly scoped to real user needs. Second, I don't want to lock future (or existing) implementations into a given internal model of extensions. We even did this for Dart Sass—the ways its extensions work isn't identical to Ruby Sass, and we got performance gains as a result. On the other hand, it's totally valid to add code like you have in your examples to a fork of Dart Sass, and use that to generate local test cases or to assist with debugging. I think that's a great strategy. On a tangential note—since you're spending time on LibSass dev, have you considered working on #2887? It's something we'd like to land in Dart Sass very soon, but we don't want to deprecate something there if it's still the only solution in LibSass. |
1fb6a0f
to
c2bb647
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few review comments on the first few files. The diff does make it difficult to do a full review.
I realize this is WIP but there are bugs that I've spotted, hoping this helps.
c1c95c8
to
de42ad1
Compare
fc89dc7
to
0393104
Compare
0393104
to
7aaabd2
Compare
This operator is only needed on values, since sass also allows to compare them.
Continued in #2908 |
Needs sass/sass-spec#1396
This PR and Text is in flux and (hopefully) updated regularly.
This is probably the biggest refactoring after bringing reference counted
memory objects to libsass -> https://github.com/sass/libsass/pull/2222/files.
So far I invested around 60h for this refactoring, and I estimate that it needs
around 120h more to finish from here. The main goals here are:
ToDo:
@extend
and drop "Node" classAlready Done:
Main pain points:
between old and new representation, since extend is meant to update the existing
reference (if we do it on a copy, the result will never be in the resulting css).
But I can make a start at
selector-extend
function. Once I have that one right I cantry to change the real extend logic to use the new implementation (current ToDo).
But we have to exchange the whole implementation at once, so for now I try
to reliably convert small functions from dart-sass to libsass.
What went well
Get rid of or "normalize" parent selector use
When I first fixed/improved/implemented parent resolving I wasn't ware of all the
subtle details how sass handles those, so I made a few logic errors here and there.
The linked-list nature of complex selectors also added to that confusion. With the new
implementation we should get a clear understanding of implicit and explicit parent selectors.
The goal for this new implementation is to get rid of explicit parent selector objects (we had
them as fake and real ones). New we have
ComplexSelector->chroots
(TBD) andCompoundSelector->hasRealParent
(TBD). These boolean options replace all the"FAKE" (implicit)
Parent_Selector
instances. It might also be worth mentioning thata
CompoundSelector
can only have an explicit parent at the beginning and musterrror if seen at any other position, so the boolean flag matches exactly that. On the
other hand any parent context will define if a
SelectorList
should be connected toits parent on the stack or not (e.g.
@at-root
), so thechroots
option fits here well.CompoundSelector->hasRealParent()
- The compound selector (list of simple selectors)starts with an explicit parent selector (e.g.
&.foo
).ComplexSelector->chroots()
- If true, don't connect to parent on stack (formerly fake parent).Parent_Selector
should only be seen in interpolations. But I still have to seeif we need to treat interpolations different from regular parent selectors (we probably do).
New selector structure (equal to dart sass)
SelectorList
is an array ofComplexSelector
ComplexSelector
is an array ofCompoundOrCombinator
CompoundOrCombinator
is aspace
SelectorCombinator
is either>
,+
or~
CompoundSelector
in an array ofSimple_Selector
ID_Selector
)And btw. if somebody wants to sponsor such efforts, I do have a paypal account :)