Clamp saturation and lightness rather than throwing errors (#521)

This matches Ruby Sass's behavior.
This commit is contained in:
Natalie Weizenbaum 2018-11-12 14:25:40 -08:00 committed by GitHub
parent 4520b8b53b
commit 13006e9902
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -10,6 +10,10 @@
command-line interface, Dart API, and JS API. These load paths are checked command-line interface, Dart API, and JS API. These load paths are checked
just after the load paths explicitly passed by the user. just after the load paths explicitly passed by the user.
* Allow saturation and lightness values outside of the `0%` to `100%` range in
the `hsl()` and `hsla()` functions. They're now clamped to be within that
range rather than producing an error if they're outside it.
* Properly compile selectors that end in escaped whitespace. * Properly compile selectors that end in escaped whitespace.
[content-args]: https://github.com/sass/language/blob/master/accepted/content-args.md [content-args]: https://github.com/sass/language/blob/master/accepted/content-args.md

View File

@ -174,7 +174,8 @@ final List<BuiltInCallable> coreFunctions = new UnmodifiableListView([
var saturation = arguments[1].assertNumber("saturation"); var saturation = arguments[1].assertNumber("saturation");
var lightness = arguments[2].assertNumber("lightness"); var lightness = arguments[2].assertNumber("lightness");
return new SassColor.hsl(hue.value, saturation.value, lightness.value); return new SassColor.hsl(hue.value, saturation.value.clamp(0, 100),
lightness.value.clamp(0, 100));
}, },
r"$hue, $saturation": (arguments) { r"$hue, $saturation": (arguments) {
// hsl(123, var(--foo)) is valid CSS because --foo might be `10%, 20%` and // hsl(123, var(--foo)) is valid CSS because --foo might be `10%, 20%` and
@ -208,7 +209,10 @@ final List<BuiltInCallable> coreFunctions = new UnmodifiableListView([
var lightness = arguments[2].assertNumber("lightness"); var lightness = arguments[2].assertNumber("lightness");
var alpha = arguments[3].assertNumber("alpha"); var alpha = arguments[3].assertNumber("alpha");
return new SassColor.hsl(hue.value, saturation.value, lightness.value, return new SassColor.hsl(
hue.value,
saturation.value.clamp(0, 100),
lightness.value.clamp(0, 100),
_percentageOrUnitless(alpha, 1, "alpha")); _percentageOrUnitless(alpha, 1, "alpha"));
}, },
r"$hue, $saturation, $lightness": (arguments) { r"$hue, $saturation, $lightness": (arguments) {