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

Deprecate math.random() when $limit has units #1779

Merged
merged 5 commits into from
Aug 18, 2022
Merged
Changes from 1 commit
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
18 changes: 15 additions & 3 deletions lib/src/functions/math.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,23 @@ final _random = math.Random();

final _randomFunction = _function("random", r"$limit: null", (arguments) {
if (arguments[0] == sassNull) return SassNumber(_random.nextDouble());
var limit = arguments[0].assertNumber("limit").assertInt("limit");
if (limit < 1) {
var limit = arguments[0].assertNumber("limit");

if (limit.hasUnits) {
warn(
"math.random() will no longer ignore \$limit units ($limit) in a "
"future release.\n"
"\n"
"If you meant to preserve units: "
Goodwine marked this conversation as resolved.
Show resolved Hide resolved
"math.random($limit) * 1${limit.unitString}",
Goodwine marked this conversation as resolved.
Show resolved Hide resolved
Goodwine marked this conversation as resolved.
Show resolved Hide resolved
);
}

var limitScalar = limit.assertInt("limit");
if (limitScalar < 1) {
throw SassScriptException("\$limit: Must be greater than 0, was $limit.");
}
return SassNumber(_random.nextInt(limit) + 1);
return SassNumber(_random.nextInt(limitScalar) + 1);
});

final _div = _function("div", r"$number1, $number2", (arguments) {
Expand Down