Tighten the span around index operators.
Splitting after "[" rarely looks good. Trying this out on a real
corpus seems to improve every affected case I saw.
R=kevmoo@google.com
Review URL: https://codereview.chromium.org//2525553003 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 113306b..dfaf086 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
* Add support for assert() in constructor initializers.
* Correctly indent the right-hand side of `is` and `as` expressions.
+* Avoid splitting in index operators when possible.
# 0.2.11+1
diff --git a/lib/src/chunk.dart b/lib/src/chunk.dart
index da6d7bb..0ac36bd 100644
--- a/lib/src/chunk.dart
+++ b/lib/src/chunk.dart
@@ -329,6 +329,9 @@
/// Splitting on the "." in a named constructor.
static const constructorName = 3;
+ /// Splitting a `[...]` index operator.
+ static const index = 3;
+
/// Splitting before a type argument or type parameter.
static const typeArgument = 4;
}
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index f10cdd0..2bc844b 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1207,7 +1207,7 @@
soloZeroSplit();
}
- builder.startSpan();
+ builder.startSpan(Cost.index);
token(node.leftBracket);
soloZeroSplit();
visit(node.index);
diff --git a/test/regression/other/angular.unit b/test/regression/other/angular.unit
index add59be..85b76c8 100644
--- a/test/regression/other/angular.unit
+++ b/test/regression/other/angular.unit
@@ -42,4 +42,20 @@
'ondone': '&onDone',
'on-optional': '&onOptional'
})
-class IoControllerComponent implements ScopeAware {}
\ No newline at end of file
+class IoControllerComponent implements ScopeAware {}
+>>> (indent 4)
+ main() {
+ expect(matcher.match(
+ CssSelector.parse("someOtherTag.someOtherClass[someOtherAttr]")[
+ 0],
+ selectableCollector))
+ .toEqual(false);
+ }
+<<<
+ main() {
+ expect(matcher.match(
+ CssSelector
+ .parse("someOtherTag.someOtherClass[someOtherAttr]")[0],
+ selectableCollector))
+ .toEqual(false);
+ }
\ No newline at end of file