anchor.diff:        }
       }
   
  +    if (extended == null) {
  +      return identical(original, compound)
  +          ? null
  +          : [
  +              new ComplexSelector([original])
  +            ];
  +    } else if (!identical(original, compound)) {
  +      if (replace) {
  +        extended.insert(0, new ComplexSelector([original]));
  +      } else {
  +        extended[0] = new ComplexSelector([original]);
  +      }
  +    }
  +
       return extended;
  +  }
  +
  +  List<PseudoSelector> _extendPseudo(
  +      PseudoSelector pseudo, Map<SimpleSelector, Set<ExtendSource>> extensions,
  +      {bool replace: false}) {
  +    // TODO: avoid recursive loops when extending.
  +    var extended = _extendList(pseudo.selector, extensions, replace: replace);
  +    if (extended == null) return null;
  +
  +    // TODO: what do we do about placeholders in the selector? If we just
  +    // eliminate them here, what happens to future extends?
  +
  +    // For `:not()`, we usually want to get rid of any complex selectors because
  +    // that will cause the selector to fail to parse on all browsers at time of
  +    // writing. We can keep them if either the original selector had a complex
  +    // selector, or the result of extending has only complex selectors, because
  +    // either way we aren't breaking anything that isn't already broken.
  +    Iterable<ComplexSelector> complexes = extended.components;
  +    if (pseudo.normalizedName == "not" &&
  +        !pseudo.selector.components
  +            .any((complex) => complex.components.length > 1) &&
  +        extended.components.any((complex) => complex.components.length == 1)) {
  +      complexes = extended.components
  +          .where((complex) => complex.components.length <= 1);
  +    }
  +
  +    complexes = complexes.expand((complex) {
  +      if (complex.components.length != 1) return [complex];
  +      if (complex.components.first is! CompoundSelector) return [complex];
  +      var compound = complex.components.first as CompoundSelector;
  +      if (compound.components.length != 1) return [complex];
  +      if (compound.components.first is! PseudoSelector) return [complex];
  +      var innerPseudo = compound.components.first as PseudoSelector;
  +      if (innerPseudo.selector == null) return [complex];
  +
  +      switch (pseudo.normalizedName) {
  +        case 'not':
  +          // In theory, if there's a `:not` nested within another `:not`, the
  +          // inner `:not`'s contents should be unified with the return value.
  +          // For example, if `:not(.foo)` extends `.bar`, `:not(.bar)` should
  +          // become `.foo:not(.bar)`. However, this is a narrow edge case and
  +          // supporting it properly would make this code and the code calling it
  +          // a lot more complicated, so it's not supported for now.
  +          if (innerPseudo.normalizedName != 'matches') return [];
  +          return innerPseudo.selector.components;
  +
  +        case 'matches':
  +        case 'any':
  +        case 'current':
  +        case 'nth-child':
  +        case 'nth-last-child':
  +          // As above, we could theoretically support :not within :matches, but
  +          // doing so would require this method and its callers to handle much
  +          // more complex cases that likely aren't worth the pain.
  +          if (innerPseudo.name != pseudo.name) return [];
  +          if (innerPseudo.argument != pseudo.argument) return [];
  +          return innerPseudo.selector.components;
  +
  +        case 'has':
  +        case 'host':
  +        case 'host-context':
  +          // We can't expand nested selectors here, because each layer adds an
  +          // additional layer of semantics. For example, `:has(:has(img))`
  +          // doesn't match `<div><img></div>` but `:has(img)` does.
  +          return [complex];
  +
  +        default:
  +          return [];
  +      }
  +    });
  +
  +    // Older browsers support `:not`, but only with a single complex selector.
  +    // In order to support those browsers, we break up the contents of a `:not`
  +    // unless it originally contained a selector list.
  +    if (pseudo.normalizedName == 'not' &&
  +        pseudo.selector.components.length == 1) {
  +      return complexes
  +          .map((complex) => pseudo.withSelector(new SelectorList([complex])))
  +          .toList();
  +    } else {
  +      return [pseudo.withSelector(new SelectorList(complexes))];
  +    }
     }
   
     List<ComplexSelector> _trim(List<List<ComplexSelector>> lists) {
  
positive.code:               : unifyCompound(extenderBase.components, compoundWithoutSimple);
            if (unified == null) continue;
  
            if (!changed) {
              extended = replace
                  ? []
                  : [
                      new ComplexSelector([compound])
                    ];
            }
            changed = true;
            extended.add(new ComplexSelector(
                complex.components.take(complex.components.length - 1).toList()
                  ..add(unified),
  
negative.code:     }
  
      if (_extensions.isNotEmpty) {
        selector =
            new CssValue(_extendList(selector.value, _extensions), selector.span);
      }
      var rule = new CssStyleRule(selector, span);
      _registerSelector(selector.value, rule);
  
      return rule;
    }
  
    void _registerSelector(SelectorList list, CssStyleRule rule) {
      for (var complex in list.components) {
        for (var component in complex.components) {
          if (component is CompoundSelector) {
            for (var simple in component.components) {
              _selectors.putIfAbsent(simple, () => new Set()).add(rule);
  
              if (simple is PseudoSelector && simple.selector != null) {
                _registerSelector(simple.selector, rule);
              }
            }
          }
        }
      }
    }
  
    void addExtension(
  