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

Merged
merged 4 commits into from
Aug 20, 2025
Merged
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: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.91.0

* **Potentially breaking change:** `meta.inspect()` (as well as other systems
that use it such as `@debug` and certain error messages) now emits numbers
with as high precision as is available instead of rounding to the nearest
1e⁻¹⁰ as we do when serializing to CSS. This better fits the purpose of
`meta.inspect()`, which is to provide full information about the structure of
a Sass value.

## 1.90.0

* Allow a `@forward`ed module to be loaded with a configuration when that module
Expand Down
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
11 changes: 10 additions & 1 deletion lib/src/visitor/serialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,10 @@ 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?) {
if (fuzzyAsInt(number) case var integer?
// In inspect mode, we want to show the full precision of every number,
// so we only write them as integers when they're precisely equal.
when !_inspect || number == integer) {
// JS still uses exponential notation for integers, so we have to handle
// it here.
buffer.write(_removeExponent(integer.toString()));
Expand All @@ -1201,6 +1204,12 @@ final class _SerializeVisitor

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
4 changes: 4 additions & 0 deletions pkg/sass-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.26

* No user-visible changes.

## 0.4.25

* No user-visible changes.
Expand Down
2 changes: 1 addition & 1 deletion pkg/sass-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-parser",
"version": "0.4.25",
"version": "0.4.26",
"description": "A PostCSS-compatible wrapper of the official Sass parser",
"repository": "sass/sass",
"author": "Google Inc.",
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 15.9.0

* No user-visible changes.

## 15.8.0

* No user-visible changes.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 15.8.0
version: 15.9.0
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: ">=3.6.0 <4.0.0"

dependencies:
sass: 1.90.0
sass: 1.91.0

dev_dependencies:
dartdoc: ^8.0.14
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.90.0
version: 1.91.0
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down
Loading