Method: Sass::Script::Value::Helpers#parse_compound_selector

Defined in:
lib/sass/script/value/helpers.rb

#parse_compound_selector(value, name = nil, allow_parent_ref = false) ⇒ Sass::Selector::SimpleSequence

Parses a user-provided compound selector.

A compound selector cannot contain combinators or commas.

Parameters:

  • value (Sass::Script::Value::String)

    The selector to parse.

  • name (Symbol, nil) (defaults to: nil)

    If provided, the name of the selector argument. This is used for error reporting.

  • allow_parent_ref (Boolean) (defaults to: false)

    Whether the parsed selector should allow parent references.

Returns:

Raises:

  • (ArgumentError)

Since:

  • 3.3.0

[View source]

191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/sass/script/value/helpers.rb', line 191

def parse_compound_selector(value, name = nil, allow_parent_ref = false)
  assert_type value, :String, name
  selector = parse_selector(value, name, allow_parent_ref)
  seq = selector.members.first
  sseq = seq.members.first
  if selector.members.length == 1 && seq.members.length == 1 &&
      sseq.is_a?(Sass::Selector::SimpleSequence)
    return sseq
  end

  err = "#{value.inspect} is not a compound selector"
  err = "$#{name.to_s.tr('_', '-')}: #{err}" if name
  raise ArgumentError.new(err)
end