Skip to content

Commit 06c7e52

Browse files
authored
Avoid adding colon for track in 3rd expression of for blocks (#15887)
1 parent 5c6450d commit 06c7e52

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#### Avoid adding colon for `track` in 3rd expression of `for` blocks (#15887 by @sosukesuzuki)
2+
3+
<!-- prettier-ignore -->
4+
```html
5+
<!-- Input -->
6+
@for (item of items; let i = $index; track block) {}
7+
8+
<!-- Prettier stable -->
9+
@for (item of items; let i = $index; track: block) {}
10+
11+
<!-- Prettier main -->
12+
@for (item of items; let i = $index; track block) {}
13+
```

src/language-js/print/angular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function printAngular(path, options, print) {
6666
(node.key.name === "then" ||
6767
node.key.name === "else" ||
6868
node.key.name === "as")) ||
69-
(index === 2 &&
69+
((index === 2 || index === 3) &&
7070
((node.key.name === "else" &&
7171
parent.body[index - 1].type === "NGMicrosyntaxKeyedExpression" &&
7272
parent.body[index - 1].key.name === "then") ||

tests/format/angular/control-flow/__snapshots__/jsfmt.spec.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ item of
285285
<div *ngFor="item of items; track item"></div>
286286
</div>
287287
288+
<div>
289+
@for (item of items; let i = $index; track block) {}
290+
291+
<div *ngFor="item of items; let i = $index; track block"></div>
292+
</div>
293+
288294
=====================================output=====================================
289295
<ul>
290296
@for (let item of items; index as i; trackBy: trackByFn) {
@@ -332,6 +338,12 @@ item of
332338
<div *ngFor="item of items; track item"></div>
333339
</div>
334340
341+
<div>
342+
@for (item of items; let i = $index; track block) {}
343+
344+
<div *ngFor="item of items; let i = $index; track block"></div>
345+
</div>
346+
335347
================================================================================
336348
`;
337349

tests/format/angular/control-flow/for.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@
5252

5353
<div *ngFor="item of items; track item"></div>
5454
</div>
55+
56+
<div>
57+
@for (item of items; let i = $index; track block) {}
58+
59+
<div *ngFor="item of items; let i = $index; track block"></div>
60+
</div>

0 commit comments

Comments
 (0)