assertSelector method

SelectorList assertSelector({
  1. String? name,
  2. bool allowParent = false,
})

Parses this as a selector list, in the same manner as the selector-parse() function.

Throws a SassScriptException if this isn't a type that can be parsed as a selector, or if parsing fails. If allowParent is true, this allows ParentSelectors. Otherwise, they're considered parse errors.

If this came from a function argument, name is the argument name (without the $). It's used for error reporting.

Implementation

SelectorList assertSelector({String? name, bool allowParent = false}) {
  var string = _selectorString(name);
  try {
    return SelectorList.parse(string, allowParent: allowParent);
  } on SassFormatException catch (error, stackTrace) {
    // TODO(nweiz): colorize this if we're running in an environment where
    // that works.
    throwWithTrace(
        SassScriptException(
            error.toString().replaceFirst("Error: ", ""), name),
        error,
        stackTrace);
  }
}