mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-22 05:41:14 +01:00
Simplify specificity propagation.
A simple selector's source specificity should only come from its original complex selector, and shouldn't be modified by extensions.
This commit is contained in:
parent
9cfbf79f47
commit
4193b6346b
@ -159,7 +159,10 @@ class Extender {
|
||||
for (var component in complex.components) {
|
||||
if (component is CompoundSelector) {
|
||||
for (var simple in component.components) {
|
||||
_sourceSpecificity[simple] = complex.maxSpecificity;
|
||||
// Only source specificity for the original selector is relevant.
|
||||
// Selectors generated by `@extend` don't get new specificity.
|
||||
_sourceSpecificity.putIfAbsent(
|
||||
simple, () => complex.maxSpecificity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -419,11 +422,10 @@ class Extender {
|
||||
specificity = math.max(specificity, state.specificity);
|
||||
}
|
||||
|
||||
return complexes.map((components) {
|
||||
var complex = new ComplexSelector(components, lineBreak: lineBreak);
|
||||
_addSourceSpecificity(complex, specificity);
|
||||
return complex;
|
||||
}).toList();
|
||||
return complexes
|
||||
.map((components) =>
|
||||
new ComplexSelector(components, lineBreak: lineBreak))
|
||||
.toList();
|
||||
});
|
||||
|
||||
return _trim(unifiedPaths.where((complexes) => complexes != null).toList());
|
||||
@ -598,10 +600,8 @@ class Extender {
|
||||
var maxSpecificity = 0;
|
||||
for (var component in complex1.components) {
|
||||
if (component is CompoundSelector) {
|
||||
for (var simple in component.components) {
|
||||
maxSpecificity =
|
||||
math.max(maxSpecificity, _sourceSpecificity[simple] ?? 0);
|
||||
}
|
||||
maxSpecificity =
|
||||
math.max(maxSpecificity, _sourceSpecificityFor(component));
|
||||
}
|
||||
}
|
||||
|
||||
@ -630,19 +630,6 @@ class Extender {
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Adds [specificity] to the [_sourceSpecificity] for all simple selectors in [complex].
|
||||
void _addSourceSpecificity(ComplexSelector complex, int specificity) {
|
||||
if (specificity == 0) return;
|
||||
for (var component in complex.components) {
|
||||
if (component is CompoundSelector) {
|
||||
for (var simple in component.components) {
|
||||
_sourceSpecificity[simple] =
|
||||
math.max(_sourceSpecificity[simple] ?? 0, specificity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the maximum specificity for sources that went into producing
|
||||
/// [compound].
|
||||
int _sourceSpecificityFor(CompoundSelector compound) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user