Skip to content

Commit 1df71a5

Browse files
ntkmenex3
andauthored
Print non-integer number at full precision in inspect mode (#2615)
Co-authored-by: Natalie Weizenbaum <[email protected]>
1 parent e0b2a50 commit 1df71a5

File tree

8 files changed

+36
-9
lines changed

8 files changed

+36
-9
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 1.91.0
2+
3+
* **Potentially breaking change:** `meta.inspect()` (as well as other systems
4+
that use it such as `@debug` and certain error messages) now emits numbers
5+
with as high precision as is available instead of rounding to the nearest
6+
1e⁻¹⁰ as we do when serializing to CSS. This better fits the purpose of
7+
`meta.inspect()`, which is to provide full information about the structure of
8+
a Sass value.
9+
110
## 1.90.0
211

312
* Allow a `@forward`ed module to be loaded with a configuration when that module

lib/src/functions/color.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ final global = UnmodifiableListView([
170170
warnForDeprecation(
171171
"adjust-hue() is deprecated. Suggestion:\n"
172172
"\n"
173-
"color.adjust(\$color, \$hue: $suggestedValue)\n"
173+
"color.adjust(\$color, \$hue: ${suggestedValue.toCssString()})\n"
174174
"\n"
175175
"More info: https://sass-lang.com/d/color-functions",
176176
Deprecation.colorFunctions,
@@ -2019,7 +2019,7 @@ String _suggestScaleAndAdjust(
20192019
var factorNumber = SassNumber(factor * 100, '%');
20202020
suggestion += "s:\n"
20212021
"\n"
2022-
"color.scale(\$color, \$$channelName: $factorNumber)\n";
2022+
"color.scale(\$color, \$$channelName: ${factorNumber.toCssString()})\n";
20232023
} else {
20242024
suggestion += ":\n\n";
20252025
}
@@ -2028,7 +2028,8 @@ String _suggestScaleAndAdjust(
20282028
adjustment,
20292029
channel == ColorChannel.alpha ? null : '%',
20302030
);
2031-
return suggestion + "color.adjust(\$color, \$$channelName: $difference)";
2031+
return suggestion +
2032+
"color.adjust(\$color, \$$channelName: ${difference.toCssString()})";
20322033
}
20332034

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

lib/src/visitor/serialize.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,10 @@ final class _SerializeVisitor
11921192

11931193
// Dart always converts integers to strings in the obvious way, so all we
11941194
// have to do is clamp doubles that are close to being integers.
1195-
if (fuzzyAsInt(number) case var integer?) {
1195+
if (fuzzyAsInt(number) case var integer?
1196+
// In inspect mode, we want to show the full precision of every number,
1197+
// so we only write them as integers when they're precisely equal.
1198+
when !_inspect || number == integer) {
11961199
// JS still uses exponential notation for integers, so we have to handle
11971200
// it here.
11981201
buffer.write(_removeExponent(integer.toString()));
@@ -1201,6 +1204,12 @@ final class _SerializeVisitor
12011204

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

1207+
// Write the number at full precision in inspect mode.
1208+
if (_inspect) {
1209+
buffer.write(text);
1210+
return;
1211+
}
1212+
12041213
// Any double that's less than `SassNumber.precision + 2` digits long is
12051214
// guaranteed to be safe to emit directly, since it'll contain at most `0.`
12061215
// followed by [SassNumber.precision] digits.

pkg/sass-parser/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.26
2+
3+
* No user-visible changes.
4+
15
## 0.4.25
26

37
* No user-visible changes.

pkg/sass-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-parser",
3-
"version": "0.4.25",
3+
"version": "0.4.26",
44
"description": "A PostCSS-compatible wrapper of the official Sass parser",
55
"repository": "sass/sass",
66
"author": "Google Inc.",

pkg/sass_api/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 15.9.0
2+
3+
* No user-visible changes.
4+
15
## 15.8.0
26

37
* No user-visible changes.

pkg/sass_api/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: sass_api
22
# Note: Every time we add a new Sass AST node, we need to bump the *major*
33
# version because it's a breaking change for anyone who's implementing the
44
# visitor interface(s).
5-
version: 15.8.0
5+
version: 15.9.0
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

99
environment:
1010
sdk: ">=3.6.0 <4.0.0"
1111

1212
dependencies:
13-
sass: 1.90.0
13+
sass: 1.91.0
1414

1515
dev_dependencies:
1616
dartdoc: ^8.0.14

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.90.0
2+
version: 1.91.0
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

0 commit comments

Comments
 (0)