Commit 9a8a342
authored
Don't drop comments in collection literals with preserved newlines. (#1587)
A line comment in a collection literal triggers special formatting
where we allow multiple elements in a single line, like:
```
list = [
// Comment.
1, 2, 3
4, 5,
6,
];
```
The formatter models that by having a DelimitedListBuilder for the
entire collection literal. Then the elements that should be packed onto
a single line are formatted using a separate DelimitedListBuilder for
each line.
In the very rare case where you have a comment after the last element
on a line but *before* the subsequent comma, the comment would get
dropped. This is because the comment was sitting in the inner
DelimitedListBuilder for the line waiting to be put somewhere, but we
then discard that builder to start a new line or when the whole list is
done.
This fixes that. Whenever we're done with a line, we hoist any remaining
comments up to the outer DelimitedListBuilder. That way the comment gets
put after the comma at the end of the line.
Also bump the min SDK constraint to 3.4.0. I don't think dart_style
works with an older version because of analyzer's SDK constraints.
Fix #1584.1 parent 89577e7 commit 9a8a342
File tree
5 files changed
+491
-4
lines changed- lib/src/front_end
- test/tall
- expression
- regression/1500
5 files changed
+491
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
141 | 155 | | |
142 | 156 | | |
143 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1082 | 1082 | | |
1083 | 1083 | | |
1084 | 1084 | | |
1085 | | - | |
| 1085 | + | |
1086 | 1086 | | |
1087 | 1087 | | |
1088 | 1088 | | |
| |||
1097 | 1097 | | |
1098 | 1098 | | |
1099 | 1099 | | |
1100 | | - | |
| 1100 | + | |
| 1101 | + | |
1101 | 1102 | | |
1102 | 1103 | | |
1103 | 1104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
0 commit comments