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

Extending selectors from other modules using @use #2494

Closed
vikigenius opened this issue Jan 18, 2025 · 1 comment
Closed

Extending selectors from other modules using @use #2494

vikigenius opened this issue Jan 18, 2025 · 1 comment

Comments

@vikigenius
Copy link

I am going through the codebase and looking at how the extend algorithm works

void addExtension(
SelectorList extender, SimpleSelector target, ExtendRule extend,
[List<CssMediaQuery>? mediaContext]) {
var selectors = _selectors[target];
var existingExtensions = _extensionsByExtender[target];
Map<ComplexSelector, Extension>? newExtensions;
var sources = _extensions.putIfAbsent(target, () => {});
for (var complex in extender.components) {
if (complex.isUseless) continue;
var extension = Extension(complex, target, extend.span,
mediaContext: mediaContext, optional: extend.isOptional);
if (sources[complex] case var existingExtension?) {
// If there's already an extend from [extender] to [target], we don't need
// to re-run the extension. We may need to mark the extension as
// mandatory, though.
sources[complex] = MergedExtension.merge(existingExtension, extension);
continue;
}
sources[complex] = extension;
for (var simple in _simpleSelectors(complex)) {
_extensionsByExtender.putIfAbsent(simple, () => []).add(extension);
// Only source specificity for the original selector is relevant.
// Selectors generated by `@extend` don't get new specificity.
_sourceSpecificity.putIfAbsent(simple, () => complex.specificity);
}
if (selectors != null || existingExtensions != null) {
newExtensions ??= {};
newExtensions[complex] = extension;
}
}
if (newExtensions == null) return;
var newExtensionsByTarget = {target: newExtensions};
if (existingExtensions != null) {
var additionalExtensions =
_extendExistingExtensions(existingExtensions, newExtensionsByTarget);
if (additionalExtensions != null) {
mapAddAll2(newExtensionsByTarget, additionalExtensions);
}
}
if (selectors != null) {
_extendExistingSelectors(selectors, newExtensionsByTarget);
}
}

It's not very clear to me how this handles extending selectors from other modules.

If someone can point me in the right direction it would be very helpful

@nex3
Copy link
Contributor

nex3 commented Jan 21, 2025

Cross-module extensions are handled just before the CSS for the final stylesheet is combined and produced, in the AsyncEvaluator._extendModules() function.

@nex3 nex3 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2025
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

No branches or pull requests

2 participants