diff --git a/changelog_unreleased/angular/20051.md b/changelog_unreleased/angular/20051.md new file mode 100644 index 000000000..ca6a350c9 --- /dev/null +++ b/changelog_unreleased/angular/20051.md @@ -0,0 +1,13 @@ +#### Preserve Angular `ngIf` microsyntax keywords after `let` declarations (#20051 by @splincode) + + +```html + +
+ + + + + + +``` diff --git a/src/language-js/print/angular.js b/src/language-js/print/angular.js index 0e197d0c8..90237c4eb 100644 --- a/src/language-js/print/angular.js +++ b/src/language-js/print/angular.js @@ -54,16 +54,11 @@ function printAngular(path, options, print) { const shouldNotPrintColon = isNgForOf(path) || isNgForOfTrack(path) || - (((index === 1 && + (parent.body[0].type === "NGMicrosyntaxExpression" && (node.key.name === "then" || 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 === "track"))) && - parent.body[0].type === "NGMicrosyntaxExpression"); + node.key.name === "as" || + (index === 2 && node.key.name === "track"))); return [ print("key"), shouldNotPrintColon ? " " : ": ", diff --git a/tests/format/angular/ng-if-microsyntax/__snapshots__/format.test.js.snap b/tests/format/angular/ng-if-microsyntax/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..2ab0cad11 --- /dev/null +++ b/tests/format/angular/ng-if-microsyntax/__snapshots__/format.test.js.snap @@ -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====================================== + + + + +@if (tab.eventCount$ | async; as count) { +