Update CHANGELOG and add more tests.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 63249e0..29af03e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
* Support triple-shift `>>>` and `>>>=` operators (#992).
* Support non-function type aliases (#993).
+* Less indentation on nested `?:` (#713, #722).
# 2.0.0
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 7678743..6f7365c 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -821,9 +821,9 @@
@override
void visitConditionalExpression(ConditionalExpression node) {
- // Don't nest if this expression is the else leg of another ternary
- final shouldNest = !(node.parent is ConditionalExpression &&
- (node.parent as ConditionalExpression).elseExpression == node);
+ // Flatten else-if style chained conditionals.
+ var shouldNest = node.parent is! ConditionalExpression ||
+ (node.parent as ConditionalExpression).elseExpression != node;
if (shouldNest) builder.nestExpression();
// Start lazily so we don't force the operator to split if a line comment
diff --git a/test/regression/0400/0407.unit b/test/regression/0400/0407.unit
index 17eec73..f783054 100644
--- a/test/regression/0400/0407.unit
+++ b/test/regression/0400/0407.unit
@@ -12,6 +12,24 @@
..tags = (new Account_Tags()
..accountHotlist.add(new Hotlist()..hotlistId = new Int64(10))));
}
+>>> (indent 4)
+main() {
+receiver
+ ..formattedTotal = _total == 0
+ ? ""
+ : _chartType == "PieChart"
+ ? _formatter.formatAsPercent(item.value / _total, fractionDigits: 1)
+ : _formatter.formatValue(item.value, item.valueType);
+}
+<<<
+ main() {
+ receiver
+ ..formattedTotal = _total == 0
+ ? ""
+ : _chartType == "PieChart"
+ ? _formatter.formatAsPercent(item.value / _total, fractionDigits: 1)
+ : _formatter.formatValue(item.value, item.valueType);
+ }
>>> (indent 6)
main() {
receiver
diff --git a/test/regression/0700/0713.stmt b/test/regression/0700/0713.stmt
new file mode 100644
index 0000000..4a47471
--- /dev/null
+++ b/test/regression/0700/0713.stmt
@@ -0,0 +1,12 @@
+>>>
+String type = status == 'OK'
+ ? 'notices'
+ : status == 'NO' ? 'warnings' : status == 'BAD' ? 'errors' : '';
+<<<
+String type = status == 'OK'
+ ? 'notices'
+ : status == 'NO'
+ ? 'warnings'
+ : status == 'BAD'
+ ? 'errors'
+ : '';
\ No newline at end of file
diff --git a/test/regression/0700/0722.stmt b/test/regression/0700/0722.stmt
new file mode 100644
index 0000000..2e3e477
--- /dev/null
+++ b/test/regression/0700/0722.stmt
@@ -0,0 +1,34 @@
+>>>
+Widget(
+child: project.locked
+ ? Icon(Icons.lock)
+ : project.fav
+ ? Icon(Icons.star)
+ : project.taps == null
+ ? Icon(Icons.notifications)
+ : Text(
+ suffixNumber(project.taps),
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ fontSize: 18.0,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+);
+<<<
+Widget(
+ child: project.locked
+ ? Icon(Icons.lock)
+ : project.fav
+ ? Icon(Icons.star)
+ : project.taps == null
+ ? Icon(Icons.notifications)
+ : Text(
+ suffixNumber(project.taps),
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ fontSize: 18.0,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+);
\ No newline at end of file