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|
    next child unless child.is_a?(Tree::RuleNode)
    if prev_rule && prev_rule.children == child.children
      prev_rule.rules.first << ", #{child.rules.first}"
      next nil
    end
    fold_commas(child)
    prev_rule = child
    child
  end
  root.children.compact!
end