@warn
@warn
规则就是为此而设计的。它写成 @warn <expression>
,它会为用户打印 表达式(通常是字符串)的值,以及指示当前 mixin 或函数如何被调用的堆栈跟踪。但是,与 @error
规则 不同,它不会完全停止 Sass。
游乐场
SCSS 语法
$known-prefixes: webkit, moz, ms, o;
@mixin prefix($property, $value, $prefixes) {
@each $prefix in $prefixes {
@if not index($known-prefixes, $prefix) {
@warn "Unknown prefix #{$prefix}.";
}
-#{$prefix}-#{$property}: $value;
}
#{$property}: $value;
}
.tilt {
// Oops, we typo'd "webkit" as "wekbit"!
@include prefix(transform, rotate(15deg), wekbit ms);
}
游乐场
Sass 语法
$known-prefixes: webkit, moz, ms, o
@mixin prefix($property, $value, $prefixes)
@each $prefix in $prefixes
@if not index($known-prefixes, $prefix)
@warn "Unknown prefix #{$prefix}."
-#{$prefix}-#{$property}: $value
#{$property}: $value
.tilt
// Oops, we typo'd "webkit" as "wekbit"!
@include prefix(transform, rotate(15deg), wekbit ms)
CSS 输出
.tilt {
-wekbit-transform: rotate(15deg);
-ms-transform: rotate(15deg);
transform: rotate(15deg);
}
警告和堆栈跟踪的确切格式因实现而异。在 Dart Sass 中,它看起来像这样
Warning: Unknown prefix wekbit.
example.scss 6:7 prefix()
example.scss 16:3 root stylesheet