Fix Angular ngIf microsyntax colon formatting (#20051)
This commit is contained in:
1 parent
00ca2a308a
commit
d00ebd11d6
5 files changed
+50
-8
No files matched your search
@@ -0,0 +1,13 @@
|
|||||||
|
#### Preserve Angular `ngIf` microsyntax keywords after `let` declarations (#20051 by @splincode)
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```html
|
||||||
|
<!-- Input -->
|
||||||
|
<div *ngIf="item$ | async; let item; else loadingTemplate"></div>
|
||||||
|
|
||||||
|
<!-- Prettier stable -->
|
||||||
|
<div *ngIf="item$ | async; let item; else: loadingTemplate"></div>
|
||||||
|
|
||||||
|
<!-- Prettier main -->
|
||||||
|
<div *ngIf="item$ | async; let item; else loadingTemplate"></div>
|
||||||
|
```
|
||||||
Vendored
+3
-8
@@ -54,16 +54,11 @@ function printAngular(path, options, print) {
|
|||||||
const shouldNotPrintColon =
|
const shouldNotPrintColon =
|
||||||
isNgForOf(path) ||
|
isNgForOf(path) ||
|
||||||
isNgForOfTrack(path) ||
|
isNgForOfTrack(path) ||
|
||||||
(((index === 1 &&
|
(parent.body[0].type === "NGMicrosyntaxExpression" &&
|
||||||
(node.key.name === "then" ||
|
(node.key.name === "then" ||
|
||||||
node.key.name === "else" ||
|
node.key.name === "else" ||
|
||||||
node.key.name === "as")) ||
|
node.key.name === "as" ||
|
||||||
(index === 2 &&
|
(index === 2 && node.key.name === "track")));
|
||||||
((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 [
|
return [
|
||||||
print("key"),
|
print("key"),
|
||||||
shouldNotPrintColon ? " " : ": ",
|
shouldNotPrintColon ? " " : ": ",
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||||
|
|
||||||
|
exports[`ng-if.html format 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["angular"]
|
||||||
|
printWidth: 80 (default) |
|
||||||
|
=====================================input======================================
|
||||||
|
<div *ngIf="item$ | async; let item; else loadingTemplate"></div>
|
||||||
|
<div *ngIf="value; let item; then content; else loading"></div>
|
||||||
|
<div *ngIf="value; let first; let second; else loading"></div>
|
||||||
|
|
||||||
|
@if (tab.eventCount$ | async; as count) {
|
||||||
|
<x />
|
||||||
|
}
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
<div *ngIf="item$ | async; let item; else loadingTemplate"></div>
|
||||||
|
<div *ngIf="value; let item; then content; else loading"></div>
|
||||||
|
<div *ngIf="value; let first; let second; else loading"></div>
|
||||||
|
|
||||||
|
@if (tab.eventCount$ | async; as count) {
|
||||||
|
<x />
|
||||||
|
}
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
runFormatTest(import.meta, ["angular"]);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<div *ngIf="item$ | async; let item; else loadingTemplate"></div>
|
||||||
|
<div *ngIf="value; let item; then content; else loading"></div>
|
||||||
|
<div *ngIf="value; let first; let second; else loading"></div>
|
||||||
|
|
||||||
|
@if (tab.eventCount$ | async; as count) {
|
||||||
|
<x />
|
||||||
|
}
|
||||||
Reference in new issue
Block a user