module Less::StyleSheet::Mixin4

def build_with_sass(env)

def build_with_sass(env)
  selectors.build(env, :mixin).each do |path|
    el = path.inject(env.root) do |current, node|
      current.descend(node.selector, node) or raise MixinNameError, "#{selectors.text_value} in #{env}"
    end
    if el.is_a?(Node::Mixin::Def)
      # Calling a mixin with arguments, which gets compiled to a Sass mixin
      env << Node::Mixin::Call.new(el, [], env)
    else
      # Calling a mixin without arguments, which gets compiled to @extend
      sel = selector_str(path)
      base = selector_str(selector_base(path))
      if base == sel
        env << Node::SassNode.new(Sass::Tree::ExtendNode.new([sel]))
      else
        Haml::Util.haml_warn <<WARNING
G: Sass doesn't support mixing in selector sequences.
ing "#{sel}" with "@extend #{base}"
G
        env << Node::SassNode.new(Sass::Tree::CommentNode.new("// #{sel};", true))
        env << Node::SassNode.new(Sass::Tree::ExtendNode.new([base]))
      end
    end
  end
end

def selector_base(path)

def selector_base(path)
  el, i = Haml::Util.enum_with_index(path).to_a.reverse.find {|e, i| e.selector !~ /^:{1,2}$/} ||
    [path.first, 0]
  sel = (el.selector =~ /^:{0,2}$/ ? el.selector : "")
  [Node::Element.new(el.name, sel)] + path[i+1..-1]
end

def selector_str(path)

def selector_str(path)
  path.map {|e| e.sass_selector_str}.join(' ').gsub(' :', ':')
end