From 34d6ff3653230898e6d653f0d1f3e067906cf4e4 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Tue, 22 Nov 2016 15:11:52 -0800 Subject: [PATCH] Correctly indent the RHS of 'is' and 'as' expressions. I'm surprised this has been wrong for so long. R=kevmoo@google.com Review URL: https://codereview.chromium.org//2521383002 . --- CHANGELOG.md | 1 + lib/src/source_visitor.dart | 4 ++++ test/splitting/mixed.stmt | 14 +++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08fda231..113306bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.2.12-dev * Add support for assert() in constructor initializers. +* Correctly indent the right-hand side of `is` and `as` expressions. # 0.2.11+1 diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart index 9c4cd2c6..f10cdd07 100644 --- a/lib/src/source_visitor.dart +++ b/lib/src/source_visitor.dart @@ -159,11 +159,13 @@ class SourceVisitor implements AstVisitor { visitAsExpression(AsExpression node) { builder.startSpan(); + builder.nestExpression(); visit(node.expression); soloSplit(); token(node.asOperator); space(); visit(node.type); + builder.unnest(); builder.endSpan(); } @@ -1240,12 +1242,14 @@ class SourceVisitor implements AstVisitor { visitIsExpression(IsExpression node) { builder.startSpan(); + builder.nestExpression(); visit(node.expression); soloSplit(); token(node.isOperator); token(node.notOperator); space(); visit(node.type); + builder.unnest(); builder.endSpan(); } diff --git a/test/splitting/mixed.stmt b/test/splitting/mixed.stmt index 33cdba44..97ba5075 100644 --- a/test/splitting/mixed.stmt +++ b/test/splitting/mixed.stmt @@ -210,4 +210,16 @@ veryLongFunction() => longArgument + longArgument + longArgument; veryLongFunction() => longArgument + longArgument + - longArgument; \ No newline at end of file + longArgument; +>>> initialize with as expression +var longVariableName = identifierSoLongItWraps as SomeClassName; +<<< +var longVariableName = + identifierSoLongItWraps + as SomeClassName; +>>> initialize with is expression +var longVariableName = identifierSoLongItWraps is SomeClassName; +<<< +var longVariableName = + identifierSoLongItWraps + is SomeClassName; \ No newline at end of file