Skip to content

Print non-integer number at full precision in inspect mode #2615

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ final global = UnmodifiableListView([
warnForDeprecation(
"adjust-hue() is deprecated. Suggestion:\n"
"\n"
"color.adjust(\$color, \$hue: $suggestedValue)\n"
"color.adjust(\$color, \$hue: ${suggestedValue.toCssString()})\n"
"\n"
"More info: https://sass-lang.com/d/color-functions",
Deprecation.colorFunctions,
Expand Down Expand Up @@ -2019,7 +2019,7 @@ String _suggestScaleAndAdjust(
var factorNumber = SassNumber(factor * 100, '%');
suggestion += "s:\n"
"\n"
"color.scale(\$color, \$$channelName: $factorNumber)\n";
"color.scale(\$color, \$$channelName: ${factorNumber.toCssString()})\n";
} else {
suggestion += ":\n\n";
}
Expand All @@ -2028,7 +2028,8 @@ String _suggestScaleAndAdjust(
adjustment,
channel == ColorChannel.alpha ? null : '%',
);
return suggestion + "color.adjust(\$color, \$$channelName: $difference)";
return suggestion +
"color.adjust(\$color, \$$channelName: ${difference.toCssString()})";
}

/// Throws an error indicating that a missing channel named [name] can't be
Expand All @@ -2037,7 +2038,7 @@ Never _missingChannelError(SassColor color, String channel) =>
throw SassScriptException(
"Because the CSS working group is still deciding on the best behavior, "
"Sass doesn't currently support modifying missing channels (color: "
"$color).",
"${color.toCssString()}).",
channel,
);

Expand Down
18 changes: 14 additions & 4 deletions lib/src/visitor/serialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1193,14 +1193,24 @@ final class _SerializeVisitor
// Dart always converts integers to strings in the obvious way, so all we
// have to do is clamp doubles that are close to being integers.
if (fuzzyAsInt(number) case var integer?) {
// JS still uses exponential notation for integers, so we have to handle
// it here.
buffer.write(_removeExponent(integer.toString()));
return;
// Write the number as fuzzy integer only if not in inspect mode or if the
// number precisely equals to the fuzzy interger
if (!_inspect || number == integer) {
// JS still uses exponential notation for integers, so we have to handle
// it here.
buffer.write(_removeExponent(integer.toString()));
return;
}
}

var text = _removeExponent(number.toString());

// Write the number at full precision in inspect mode.
if (_inspect) {
buffer.write(text);
return;
}

// Any double that's less than `SassNumber.precision + 2` digits long is
// guaranteed to be safe to emit directly, since it'll contain at most `0.`
// followed by [SassNumber.precision] digits.
Expand Down
Loading