class Sass::CSS

def fold_commas(root)

Parameters:
  • rule (Tree::RuleNode) -- The candidate for flattening
def fold_commas(root)
  prev_rule = nil
  root.children.map! do |child|
    unless child.is_a?(Tree::RuleNode)
      fold_commas(child) if child.is_a?(Tree::DirectiveNode)
      next child
    end
    if prev_rule && prev_rule.children == child.children
      prev_rule.rule.first << ", #{child.rule.first}"
      next nil
    end
    fold_commas(child)
    prev_rule = child
    child
  end
  root.children.compact!
end