mixinElements method

List<String> mixinElements()

Creates _mixinElements as a String List of selector names

Example: '#sel1', '.sel2', ...

Implementation

List<String> mixinElements() {
  final re = RegExp(r'[,&#\*\.\w-]([\w-]|(\\.))*');

  if (_mixinElements != null) return _mixinElements; // cache exist

  final css = elements
      .fold(
          StringBuffer(),
          (StringBuffer prev, Element v) => prev
            ..write(v.combinator.value)
            ..write((v.value is String)
                ? v.value
                : (v.value as Node).toCSS(null)))
      .toString();

  final Iterable<Match> matchs = re.allMatches(css);
  if (matchs != null) {
    _mixinElements = matchs.map((Match m) => m[0]).toList();
    if (_mixinElements.isNotEmpty && _mixinElements[0] == '&') {
      _mixinElements.removeAt(0);
    }
  } else {
    _mixinElements = <String>[];
  }

  return _mixinElements;

//3.0.0 20170528
// Selector.prototype.mixinElements = function() {
//     if (this.mixinElements_) {
//         return this.mixinElements_;
//     }
//
//     var elements = this.elements.map( function(v) {
//         return v.combinator.value + (v.value.value || v.value);
//     }).join("").match(/[,&#\*\.\w-]([\w-]|(\\.))*/g);
//
//     if (elements) {
//         if (elements[0] === "&") {
//             elements.shift();
//         }
//     } else {
//         elements = [];
//     }
//
//     return (this.mixinElements_ = elements);
// };
}