Improve the deprecation message for /-as-division (#1561)

This also changes the string representation of ParenthesizedExpression
to fix the recommendations involving them (otherwise the calc
recommendation would be an invalid one).

Co-authored-by: Natalie Weizenbaum <nweiz@google.com>
This commit is contained in:
Christophe Coevoet 2021-11-30 02:43:08 +01:00 committed by GitHub
parent 97c51d6285
commit 3e231f784b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 10 deletions

View File

@ -1,5 +1,7 @@
## 1.44.0
* Suggest `calc()` as an alternative in `/`-as-division deprecation messages.
### Dart API
* Add `SassNumber.convert()` and `SassNumber.convertValue()`. These work like

View File

@ -23,5 +23,5 @@ class ParenthesizedExpression implements Expression {
T accept<T>(ExpressionVisitor<T> visitor) =>
visitor.visitParenthesizedExpression(this);
String toString() => expression.toString();
String toString() => "($expression)";
}

View File

@ -2125,16 +2125,18 @@ class _EvaluateVisitor
expression.operator == BinaryOperator.dividedBy) {
return "math.div(${recommendation(expression.left)}, "
"${recommendation(expression.right)})";
} else if (expression is ParenthesizedExpression) {
return expression.expression.toString();
} else {
return expression.toString();
}
}
_warn(
"Using / for division is deprecated and will be removed in "
"Dart Sass 2.0.0.\n"
"Using / for division outside of calc() is deprecated "
"and will be removed in Dart Sass 2.0.0.\n"
"\n"
"Recommendation: ${recommendation(node)}\n"
"Recommendation: ${recommendation(node)} or calc($node)\n"
"\n"
"More info and automated migrator: "
"https://sass-lang.com/d/slash-div",

View File

@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 75f2c75c86bcf5397b054a6e88d94e44e59512cf
// Checksum: 96397ede2c79b09005bbac9a013d4a6b42faf736
//
// ignore_for_file: unused_import
@ -2115,16 +2115,18 @@ class _EvaluateVisitor
expression.operator == BinaryOperator.dividedBy) {
return "math.div(${recommendation(expression.left)}, "
"${recommendation(expression.right)})";
} else if (expression is ParenthesizedExpression) {
return expression.expression.toString();
} else {
return expression.toString();
}
}
_warn(
"Using / for division is deprecated and will be removed in "
"Dart Sass 2.0.0.\n"
"Using / for division outside of calc() is deprecated "
"and will be removed in Dart Sass 2.0.0.\n"
"\n"
"Recommendation: ${recommendation(node)}\n"
"Recommendation: ${recommendation(node)} or calc($node)\n"
"\n"
"More info and automated migrator: "
"https://sass-lang.com/d/slash-div",

View File

@ -1,3 +1,7 @@
## 1.0.0-beta.20
* No user-visible changes.
## 1.0.0-beta.19
* No user-visible changes.

View File

@ -2,7 +2,7 @@ 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: 1.0.0-beta.19
version: 1.0.0-beta.20
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

View File

@ -1,5 +1,5 @@
name: sass
version: 1.44.0-dev
version: 1.44.0
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass