如何在没有 mixin 的情况下使用 Extend in stylus 获得 root

How get root with Extend in stylus without mixin

我正在学习 stylus,我需要为他的子 类:

获取根元素属性
.daddy-element
    (this is a root)
    main: prop
    &.sublclass
        (need "main: prop" here)
        another: prop

在sass中我们有$root: &,这种情况下什么手写笔可以? @mixin — 具有最大 css 代码的错误变体,阅读起来不清晰

这是我的 sass 代码: Codepen

我找到了一个带有占位符选择器的解决方案,它不像 SASS 中那样干净,但却是我可以实现的最佳解决方案:

手写笔

$placeholder
 margin-bottom: 1em

.class
  @extends $placeholder
  &.ok
     @extends $placeholder
     color: red

输出

.class,
.class.ok {
  margin-bottom: 1em;
}
.class.ok {
  color: #f00;
}