当我们有嵌套的mixin时,如何编译sass

当我们有嵌套的mixin时,如何编译sass,sass,compass-sass,Sass,Compass Sass,当我尝试使用compass编译时,我得到了一个错误,即 不能在控制指令或其他混合中定义混合 下面是我正在使用的代码 @mixin fn-menu { $triangle-height: 8px; $triangle-width: 16px; @mixin menu-marker-inner($pos: top) { $size: 12px; $offset-height: $triangle-height; ....... 在谷歌搜索

当我尝试使用compass编译时,我得到了一个错误,即 不能在控制指令或其他混合中定义混合

下面是我正在使用的代码

@mixin fn-menu {
    $triangle-height: 8px;
    $triangle-width: 16px;

    @mixin menu-marker-inner($pos: top)  {
        $size: 12px;
        $offset-height: $triangle-height;
.......
在谷歌搜索时,我发现嵌套的mixin不受支持。但这一页说,

**Smaller Improvements**

Mixins and functions may now be defined in a nested context, for example within @media rules. This also allows files containing them to be imported in such contexts.
我正在执行命令

compile sass --sass-dir sass --force
我如何解决这个问题


不幸的是,我无法更改编码样式,因为此代码来自产品。

您可以在@media rules甚至传统嵌套规则中声明mixin和函数,如下所示:

.users{
  @function user-details-width($slots){
    //Some calculation here...
  }

  @mixin user-details{
    //Some syling logic here...
    width: user-details-width(3);
  }

  .details{
    @include user-details; //This is totally OK
  }
}

a{
  @include user-details; //<<<ERROR!!!
}
当您这样做时,您的mixin和函数将在该上下文中确定范围,并且仅在相同级别或更低级别中可见


不幸的是,不能在其他mixin或函数中定义mixin和函数,甚至不能在@for、@if、@while或@each中定义控制指令。同样的限制也适用于@import指令。您可以在规则内进行导入,但不能使用if指令、任何其他控制指令或mixin和函数限制导入。

升级您的Sass版本?