class Sass::CSS

def parent_ref_rules(root)

Parameters:
  • root (Tree::Node) -- The parent node
def parent_ref_rules(root)
  current_rule = nil
  root.children.map! do |child|
    unless child.is_a?(Tree::RuleNode)
      parent_ref_rules(child) if child.is_a?(Tree::DirectiveNode)
      next child
    end
    first, rest = child.rule.first.scan(/\A(&?(?: .|[^ ])[^.#: \[]*)([.#: \[].*)?\Z/m).first
    if current_rule.nil? || current_rule.rule.first != first
      current_rule = Tree::RuleNode.new([first])
    end
    if rest
      child.rule = ["&" + rest]
      current_rule << child
    else
      current_rule.children += child.children
    end
    current_rule
  end
  root.children.compact!
  root.children.uniq!
  root.children.each { |v| parent_ref_rules(v) }
end