@error
Sass 通过 @error
规则简化了这一过程,该规则写为 @error <expression>
。它打印 表达式(通常为字符串)的值,以及指示当前 mixin 或函数如何调用的堆栈跟踪。打印错误后,Sass 会停止编译样式表,并告知正在运行它的任何系统发生了错误。
游乐场
SCSS 语法
@mixin reflexive-position($property, $value) {
@if $property != left and $property != right {
@error "Property #{$property} must be either left or right.";
}
$left-value: if($property == right, initial, $value);
$right-value: if($property == right, $value, initial);
left: $left-value;
right: $right-value;
[dir=rtl] & {
left: $right-value;
right: $left-value;
}
}
.sidebar {
@include reflexive-position(top, 12px);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Error: Property top must be either left or right.
}
游乐场
Sass 语法
@mixin reflexive-position($property, $value)
@if $property != left and $property != right
@error "Property #{$property} must be either left or right."
$left-value: if($property == right, initial, $value)
$right-value: if($property == right, $value, initial)
left: $left-value
right: $right-value
[dir=rtl] &
left: $right-value
right: $left-value
.sidebar
@include reflexive-position(top, 12px)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Error: Property top must be either left or right.
错误和堆栈跟踪的确切格式因实现而异,也可能取决于您的构建系统。这是在从命令行运行 Dart Sass 时它是什么样子
Error: "Property top must be either left or right."
╷
3 │ @error "Property #{$property} must be either left or right.";
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
example.scss 3:5 reflexive-position()
example.scss 19:3 root stylesheet