Skip to content

Commit f17c23e

Browse files
authored
Merge pull request #1019 from dart-lang/undo-flatten-conditionals
Revert the change to flatten nested conditionals.
2 parents 0067cfc + f71240c commit f17c23e

File tree

7 files changed

+38
-29
lines changed

7 files changed

+38
-29
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
* Support triple-shift `>>>` and `>>>=` operators (#992).
44
* Support non-function type aliases (#993).
5-
* Less indentation on nested `?:` (#713, #722).
65
* Correct constructor initializer indentation after `required` (#1010).
76

87
# 2.0.0

lib/src/source_visitor.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,14 @@ class SourceVisitor extends ThrowingAstVisitor {
821821

822822
@override
823823
void visitConditionalExpression(ConditionalExpression node) {
824+
// TODO(rnystrom): Consider revisiting whether users prefer this after 2.13.
825+
/*
824826
// Flatten else-if style chained conditionals.
825827
var shouldNest = node.parent is! ConditionalExpression ||
826828
(node.parent as ConditionalExpression).elseExpression != node;
827829
if (shouldNest) builder.nestExpression();
830+
*/
831+
builder.nestExpression();
828832

829833
// Start lazily so we don't force the operator to split if a line comment
830834
// appears before the first operand. If we split after one clause in a
@@ -859,7 +863,12 @@ class SourceVisitor extends ThrowingAstVisitor {
859863
builder.endRule();
860864
builder.endSpan();
861865
builder.endBlockArgumentNesting();
866+
867+
// TODO(rnystrom): Consider revisiting whether users prefer this after 2.13.
868+
/*
862869
if (shouldNest) builder.unnest();
870+
*/
871+
builder.unnest();
863872
}
864873

865874
@override

test/regression/0400/0407.unit

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,26 @@ receiver
2727
..formattedTotal = _total == 0
2828
? ""
2929
: _chartType == "PieChart"
30-
? _formatter.formatAsPercent(item.value / _total, fractionDigits: 1)
31-
: _formatter.formatValue(item.value, item.valueType);
30+
? _formatter.formatAsPercent(item.value / _total,
31+
fractionDigits: 1)
32+
: _formatter.formatValue(item.value, item.valueType);
3233
}
3334
>>> (indent 6)
3435
main() {
3536
receiver
3637
..formattedTotal = _total == 0
3738
? ""
3839
: _chartType == "PieChart"
39-
? _formatter.formatAsPercent(item.value / _total, fractionDigits: 1)
40-
: _formatter.formatValue(item.value, item.valueType);
40+
? _formatter.formatAsPercent(item.value / _total, fractionDigits: 1)
41+
: _formatter.formatValue(item.value, item.valueType);
4142
}
4243
<<<
4344
main() {
4445
receiver
4546
..formattedTotal = _total == 0
4647
? ""
4748
: _chartType == "PieChart"
48-
? _formatter.formatAsPercent(item.value / _total,
49-
fractionDigits: 1)
50-
: _formatter.formatValue(item.value, item.valueType);
49+
? _formatter.formatAsPercent(item.value / _total,
50+
fractionDigits: 1)
51+
: _formatter.formatValue(item.value, item.valueType);
5152
}

test/regression/0700/0713.stmt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ String type = status == 'OK'
66
String type = status == 'OK'
77
? 'notices'
88
: status == 'NO'
9-
? 'warnings'
10-
: status == 'BAD'
11-
? 'errors'
12-
: '';
9+
? 'warnings'
10+
: status == 'BAD'
11+
? 'errors'
12+
: '';

test/regression/0700/0722.stmt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ Widget(
2020
child: project.locked
2121
? Icon(Icons.lock)
2222
: project.fav
23-
? Icon(Icons.star)
24-
: project.taps == null
25-
? Icon(Icons.notifications)
26-
: Text(
27-
suffixNumber(project.taps),
28-
textAlign: TextAlign.center,
29-
style: TextStyle(
30-
fontSize: 18.0,
31-
fontWeight: FontWeight.w600,
32-
),
33-
),
23+
? Icon(Icons.star)
24+
: project.taps == null
25+
? Icon(Icons.notifications)
26+
: Text(
27+
suffixNumber(project.taps),
28+
textAlign: TextAlign.center,
29+
style: TextStyle(
30+
fontSize: 18.0,
31+
fontWeight: FontWeight.w600,
32+
),
33+
),
3434
);

test/regression/0900/0927.unit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class C {
77
int get currentAngleDigits => _currentSunAngleDeg < 0
88
? 1
99
: _currentSunAngleDeg < 10
10-
? 2
11-
: 3;
10+
? 2
11+
: 3;
1212
}

test/splitting/expressions.stmt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ var kind = a ? b : c ? d : e;
8484
var kind = a
8585
? b
8686
: c
87-
? d
88-
: e;
87+
? d
88+
: e;
8989
>>> don't split conditionals when indirectly nested
9090
var kind = a ? b : (c ? d : e);
9191
<<<
@@ -132,8 +132,8 @@ identifier
132132
? someParticularlyLongOperand
133133
: someParticularlyLongOperand
134134
: identifier
135-
? someParticularlyLongOperand
136-
: someParticularlyLongOperand;
135+
? someParticularlyLongOperand
136+
: someParticularlyLongOperand;
137137
>>> index expressions can split after "["
138138
verylongIdentifier[someParticularlyLongArgument];
139139
<<<

0 commit comments

Comments
 (0)