Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw proper errors for out-of-range alpha values in color.change() #2231

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,10 @@ SassColor _changeColor(
_channelForChange(channelArgs[2], color, 2),
alphaArg.andThen((alphaArg) {
if (!alphaArg.hasUnits) {
return alphaArg.value;
return alphaArg.valueInRange(0, 1, "alpha");
} else if (alphaArg.hasUnit('%')) {
return alphaArg.value / 100;
return alphaArg.valueInRangeWithUnit(0, 100, "alpha", "%") /
100;
} else {
warnForDeprecation(
"\$alpha: Passing a unit other than % ($alphaArg) is "
Expand All @@ -775,7 +776,7 @@ SassColor _changeColor(
"\n"
"See https://sass-lang.com/d/function-units",
Deprecation.functionUnits);
return alphaArg.value;
return alphaArg.valueInRange(0, 1, "alpha");
}
}) ??
color.alpha,
Expand Down
Loading