Fix @for angularControlFlowBlock (#15620)

This commit is contained in:
fisker Cheung authored and GitHub committed 2023-11-12 23:56:56 +08:00
1 parent 5c40e728e4
commit ff57f5064d
3 files changed
+27 -5

No files matched your search

+5 -3
View File
@@ -59,6 +59,7 @@ function printAngular(path, options, print) {
];
case "NGMicrosyntaxKeyedExpression": {
const { index, parent } = path;
// https://github.com/prettier/angular-estree-parser/issues/267
const shouldNotPrintColon =
isNgForOf(path) ||
(((index === 1 &&
@@ -66,9 +67,10 @@ function printAngular(path, options, print) {
node.key.name === "else" ||
node.key.name === "as")) ||
(index === 2 &&
node.key.name === "else" &&
parent.body[index - 1].type === "NGMicrosyntaxKeyedExpression" &&
parent.body[index - 1].key.name === "then")) &&
((node.key.name === "else" &&
parent.body[index - 1].type === "NGMicrosyntaxKeyedExpression" &&
parent.body[index - 1].key.name === "then") ||
node.key.name === "track"))) &&
parent.body[0].type === "NGMicrosyntaxExpression");
return [
print("key"),
@@ -278,6 +278,13 @@ item of
emptyCollection; track item.id;
"></li>
<div>
@for ( item of items; track item){
}
<div *ngFor="item of items; track item"></div>
</div>
=====================================output=====================================
<ul>
@for (let item of items; index as i; trackBy: trackByFn) {
@@ -309,7 +316,7 @@ item of
</ul>
<ul>
@for (item of emptyCollection; track: item.id) {
@for (item of emptyCollection; track item.id) {
<li>
<strong>{{ item.name }}</strong>
</li>
@@ -317,7 +324,13 @@ item of
<span>The collection is empty</span>
}
</ul>
<li *ngFor="item of emptyCollection; track: item.id"></li>
<li *ngFor="item of emptyCollection; track item.id"></li>
<div>
@for (item of items; track item) {}
<div *ngFor="item of items; track item"></div>
</div>
================================================================================
`;
@@ -45,3 +45,10 @@ i;
item of
emptyCollection; track item.id;
"></li>
<div>
@for ( item of items; track item){
}
<div *ngFor="item of items; track item"></div>
</div>