Merge pull request #907 from dart-lang/indent-multiple-variable-blocks
Indent blocks in initializers of multiple variable declarations.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3383a07..5983369 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
* Split outer nested control flow elements (#869).
* Always place a blank line after script tags (#782).
* Don't add unneeded splits on if elements near comments (#888).
+* Indent blocks in initializers of multiple-variable declarations.
# 1.3.3
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index aa74036..6ffa262 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -2698,9 +2698,16 @@
// possible, we split after *every* declaration so that each is on its own
// line.
builder.startRule();
- visitCommaSeparatedNodes(node.variables, between: split);
- builder.endRule();
+ // If there are multiple declarations split across lines, then we want any
+ // blocks in the initializers to indent past the variables.
+ if (node.variables.length > 1) builder.startBlockArgumentNesting();
+
+ visitCommaSeparatedNodes(node.variables, between: split);
+
+ if (node.variables.length > 1) builder.endBlockArgumentNesting();
+
+ builder.endRule();
_endPossibleConstContext(node.keyword);
}
diff --git a/test/regression/0900/0900.stmt b/test/regression/0900/0900.stmt
new file mode 100644
index 0000000..e3b81ff
--- /dev/null
+++ b/test/regression/0900/0900.stmt
@@ -0,0 +1,22 @@
+>>>
+void main() {
+ final f = stdin.readLineSync,
+ p = int.parse,
+ n = p(f()),
+ ranges = List.generate(n, (_) {
+ final t = f().split(' '), a = p(t[0]), b = a + p(t[1]);
+ return [a, b];
+ }),
+ dp = List<int>(n);
+}
+<<<
+void main() {
+ final f = stdin.readLineSync,
+ p = int.parse,
+ n = p(f()),
+ ranges = List.generate(n, (_) {
+ final t = f().split(' '), a = p(t[0]), b = a + p(t[1]);
+ return [a, b];
+ }),
+ dp = List<int>(n);
+}
\ No newline at end of file
diff --git a/test/splitting/variables.stmt b/test/splitting/variables.stmt
index 2dc76b6..e5b1e64 100644
--- a/test/splitting/variables.stmt
+++ b/test/splitting/variables.stmt
@@ -72,3 +72,10 @@
<<<
var x =
new XXXXXXXXXXXXXXXXXXXXXXXXXXXXX();
+>>> nest blocks when variables split
+SomeType a = () {;}, b;
+<<<
+SomeType a = () {
+ ;
+ },
+ b;
\ No newline at end of file