Skip to content

Commit

Permalink
Correctly indent the RHS of 'is' and 'as' expressions.
Browse files Browse the repository at this point in the history
I'm surprised this has been wrong for so long.

R=kevmoo@google.com

Review URL: https://codereview.chromium.org//2521383002 .
  • Loading branch information
munificent committed Nov 22, 2016
1 parent 12a34b1 commit 34d6ff3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down
14 changes: 13 additions & 1 deletion test/splitting/mixed.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,16 @@ veryLongFunction() => longArgument + longArgument + longArgument;
veryLongFunction() =>
longArgument +
longArgument +
longArgument;
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;

0 comments on commit 34d6ff3

Please sign in to comment.