Ensure space between `-` and `--`. (#607)
Fix #170.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8339230..0ef1322 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 1.0.1
+
+* Ensure space between `-` and `--` (#170).
+
# 1.0.0
* Handle mixed block and arrow bodied function arguments uniformly (#500).
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 0557d3d..22122f7 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1493,10 +1493,11 @@
visitPrefixExpression(PrefixExpression node) {
token(node.operator);
- // Corner case: put a space between successive "-" operators so we don't
- // inadvertently turn them into a "--" decrement operator.
- if (node.operand is PrefixExpression &&
- (node.operand as PrefixExpression).operator.lexeme == "-") {
+ // Edge case: put a space after "-" if the operand is "-" or "--" so we
+ // don't merge the operators.
+ var operand = node.operand;
+ if (operand is PrefixExpression &&
+ (operand.operator.lexeme == "-" || operand.operator.lexeme == "--")) {
space();
}
diff --git a/pubspec.yaml b/pubspec.yaml
index ac6c7c3..46f9a3b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: dart_style
# Note: See tool/grind.dart for how to bump the version.
-version: 1.0.0
+version: 1.0.1-dev
author: Dart Team <misc@dartlang.org>
description: Opinionated, automatic Dart source code formatter.
homepage: https://github.com/dart-lang/dart_style
diff --git a/test/regression/0100/0170.unit b/test/regression/0100/0170.unit
index 0d05465..1fcb1d8 100644
--- a/test/regression/0100/0170.unit
+++ b/test/regression/0100/0170.unit
@@ -5,4 +5,12 @@
<<<
main() {
print(- -2);
+}
+>>>
+main() {
+ var x = - --y;
+}
+<<<
+main() {
+ var x = - --y;
}
\ No newline at end of file
diff --git a/test/whitespace/expressions.stmt b/test/whitespace/expressions.stmt
index ede2fe7..d67bd89 100644
--- a/test/whitespace/expressions.stmt
+++ b/test/whitespace/expressions.stmt
@@ -89,6 +89,10 @@
- -1.2;
<<<
- -1.2;
+>>> "-" before a "--" is not joined
+- -- foo;
+<<<
+- --foo;
>>> multiline string inside nested blocks
main() {
inner() {