@mixin prepend-foo {
  $parent: &;

  @if $parent {
    .foo & {
      @content;
    }
  } @else {
    .foo {
      @content;
    }
  }
}

@include prepend-foo {
  bar {
    color: red;
  }
}

bar {
  @include prepend-foo {
    baz {
      color: red;
    }
  }
}
