assertSimpleSelector method

SimpleSelector assertSimpleSelector({
  1. String? name,
  2. bool allowParent = false,
})

Parses this as a simple selector, 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

SimpleSelector assertSimpleSelector(
    {String? name, bool allowParent = false}) {
  var string = _selectorString(name);
  try {
    return SimpleSelector.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);
  }
}