Skip to content

Commit a56085b

Browse files
committed
Add a deprecation warning for strict unary operations
Closes #1721
1 parent e2f9705 commit a56085b

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.54.10
2+
3+
* Emit a deprecation warning for `$a -$b` and `$a +$b`, since these look like
4+
they could be unary operations but they're actually parsed as binary
5+
operations. Either explicitly write `$a - $b` or `$a (-$b)`. See
6+
https://sass-lang.com/d/strict-unary for more details.
7+
18
## 1.54.9
29

310
* Fix an incorrect span in certain `@media` query deprecation warnings.

lib/src/callable/built_in.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ class BuiltInCallable implements Callable, AsyncBuiltInCallable {
7272
///
7373
/// If passed, [url] is the URL of the module in which the function is
7474
/// defined.
75-
BuiltInCallable.overloadedFunction(
76-
this.name, Map<String, Callback> overloads,
75+
BuiltInCallable.overloadedFunction(this.name, Map<String, Callback> overloads,
7776
{Object? url})
7877
: _overloads = [
7978
for (var entry in overloads.entries)

lib/src/parse/stylesheet.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,34 @@ abstract class StylesheetParser extends Parser {
17881788
} else {
17891789
singleExpression_ = BinaryOperationExpression(operator, left, right);
17901790
allowSlash = false;
1791+
1792+
if (operator == BinaryOperator.plus ||
1793+
operator == BinaryOperator.minus) {
1794+
if (scanner.string.substring(
1795+
right.span.start.offset - 1, right.span.start.offset) ==
1796+
operator.operator &&
1797+
isWhitespace(scanner.string.codeUnitAt(left.span.end.offset))) {
1798+
logger.warn(
1799+
"This operation is parsed as:\n"
1800+
"\n"
1801+
" $left ${operator.operator} $right\n"
1802+
"\n"
1803+
"but you may have intended it to mean:\n"
1804+
"\n"
1805+
" $left (${operator.operator}$right)\n"
1806+
"\n"
1807+
"Add a space after ${operator.operator} to clarify that it's "
1808+
"meant to be a binary operation, or wrap\n"
1809+
"it in parentheses to make it a unary operation. This will be "
1810+
"an error in future\n"
1811+
"versions of Sass.\n"
1812+
"\n"
1813+
"More info and automated migrator: "
1814+
"https://sass-lang.com/d/strict-unary",
1815+
span: singleExpression_!.span,
1816+
deprecation: true);
1817+
}
1818+
}
17911819
}
17921820
}
17931821

pkg/sass_api/CHANGELOG.md

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

37
* `UnaryOperationExpression`s with operator `not` now include a correct span,

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: 3.0.4
5+
version: 3.0.5-dev
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

99
environment:
1010
sdk: ">=2.17.0 <3.0.0"
1111

1212
dependencies:
13-
sass: 1.54.9
13+
sass: 1.54.10
1414

1515
dev_dependencies:
1616
dartdoc: ^5.0.0

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.54.9
2+
version: 1.54.10-dev
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

0 commit comments

Comments
 (0)