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

Add a deprecation warning for strict unary operations #1800

Merged
merged 2 commits into from Sep 15, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
## 1.55.0

* Emit a deprecation warning for `$a -$b` and `$a +$b`, since these look like
they could be unary operations but they're actually parsed as binary
operations. Either explicitly write `$a - $b` or `$a (-$b)`. See
https://sass-lang.com/d/strict-unary for more details.

### Dart API

* Add an optional `argumentName` parameter to `SassScriptException()` to make it
Expand Down
3 changes: 1 addition & 2 deletions lib/src/callable/built_in.dart
Expand Up @@ -72,8 +72,7 @@ class BuiltInCallable implements Callable, AsyncBuiltInCallable {
///
/// If passed, [url] is the URL of the module in which the function is
/// defined.
BuiltInCallable.overloadedFunction(
this.name, Map<String, Callback> overloads,
BuiltInCallable.overloadedFunction(this.name, Map<String, Callback> overloads,
{Object? url})
: _overloads = [
for (var entry in overloads.entries)
Expand Down
28 changes: 28 additions & 0 deletions lib/src/parse/stylesheet.dart
Expand Up @@ -1788,6 +1788,34 @@ abstract class StylesheetParser extends Parser {
} else {
singleExpression_ = BinaryOperationExpression(operator, left, right);
allowSlash = false;

if (operator == BinaryOperator.plus ||
operator == BinaryOperator.minus) {
if (scanner.string.substring(
right.span.start.offset - 1, right.span.start.offset) ==
operator.operator &&
isWhitespace(scanner.string.codeUnitAt(left.span.end.offset))) {
logger.warn(
"This operation is parsed as:\n"
"\n"
" $left ${operator.operator} $right\n"
"\n"
"but you may have intended it to mean:\n"
"\n"
" $left (${operator.operator}$right)\n"
"\n"
"Add a space after ${operator.operator} to clarify that it's "
"meant to be a binary operation, or wrap\n"
"it in parentheses to make it a unary operation. This will be "
"an error in future\n"
"versions of Sass.\n"
"\n"
"More info and automated migrator: "
"https://sass-lang.com/d/strict-unary",
span: singleExpression_!.span,
deprecation: true);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sass_api/pubspec.yaml
Expand Up @@ -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: 3.1.0
version: 3.1.0-dev
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: sass
version: 1.55.0
version: 1.55.0-dev
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down