sass-site/source/documentation/at-rules/warn.html.md.erb

63 lines
1.7 KiB
Plaintext
Raw Normal View History

2018-09-01 22:35:20 +02:00
---
title: "@warn"
2019-03-05 01:24:31 +01:00
introduction: >
When writing [mixins](mixin) and [functions](function), you may want to
discourage users from passing certain arguments or certain values. They may be
passing legacy arguments that are now deprecated, or they may be calling your
API in a way thats not quite optimal.
2018-09-01 22:35:20 +02:00
---
The `@warn` rule is designed just for that. It's written `@warn <expression>`
and it prints the value of the [expression][] (usually a string) for the user,
along with a stack trace indicating how the current mixin or function was
called. Unlike the [`@error` rule][], though, it doesn't stop Sass entirely.
[expression]: ../syntax/structure#expressions
[`@error` rule]: error
<% example do %>
$known-prefixes: webkit, moz, ms, o;
2018-09-01 22:35:20 +02:00
@mixin prefix($property, $value, $prefixes) {
@each $prefix in $prefixes {
@if not index($known-prefixes, $prefix) {
@warn "Unknown prefix #{$prefix}.";
}
2018-09-01 22:35:20 +02:00
-#{$prefix}-#{$property}: $value;
}
#{$property}: $value;
2018-09-01 22:35:20 +02:00
}
.tilt {
// Oops, we typo'd "webkit" as "wekbit"!
@include prefix(transform, rotate(15deg), wekbit ms);
}
===
$known-prefixes: webkit, moz, ms, o
2018-09-01 22:35:20 +02:00
@mixin prefix($property, $value, $prefixes)
@each $prefix in $prefixes
@if not index($known-prefixes, $prefix)
@warn "Unknown prefix #{$prefix}."
2018-09-01 22:35:20 +02:00
-#{$prefix}-#{$property}: $value
2018-09-01 22:35:20 +02:00
#{$property}: $value
2018-09-01 22:35:20 +02:00
.tilt
// Oops, we typo'd "webkit" as "wekbit"!
@include prefix(transform, rotate(15deg), wekbit ms)
2018-09-01 22:35:20 +02:00
<% end %>
The exact format of the warning and stack trace varies from implementation to
implementation. This is what it looks like in Dart Sass:
```
Warning: Unknown prefix wekbit.
example.scss 6:7 prefix()
example.scss 16:3 root stylesheet
```