diff --git a/changelog_unreleased/angular/17280.md b/changelog_unreleased/angular/17280.md new file mode 100644 index 000000000..567e92c8d --- /dev/null +++ b/changelog_unreleased/angular/17280.md @@ -0,0 +1,13 @@ +#### Remove extra colon after `track` in angular `@for` control-flow (#17280 by @claudio-herger) + + +```angular +// Input +@for (item of items; let i = $index; let count = $count; track block) {} + +// Prettier stable +@for (item of items; let i = $index; let count = $count; track: block) {} + +// Prettier main +@for (item of items; let i = $index; let count = $count; track block) {} +``` diff --git a/src/language-js/print/angular.js b/src/language-js/print/angular.js index cc730d054..923373c87 100644 --- a/src/language-js/print/angular.js +++ b/src/language-js/print/angular.js @@ -62,11 +62,12 @@ function printAngular(path, options, print) { // https://github.com/prettier/angular-estree-parser/issues/267 const shouldNotPrintColon = isNgForOf(path) || + isNgForOfTrack(path) || (((index === 1 && (node.key.name === "then" || node.key.name === "else" || node.key.name === "as")) || - ((index === 2 || index === 3) && + (index === 2 && ((node.key.name === "else" && parent.body[index - 1].type === "NGMicrosyntaxKeyedExpression" && parent.body[index - 1].key.name === "then") || @@ -100,6 +101,16 @@ function isNgForOf({ node, index }) { ); } +function isNgForOfTrack(path) { + const { node } = path; + return ( + path.parent.body[1].key.name === "of" && + node.type === "NGMicrosyntaxKeyedExpression" && + node.key.name === "track" && + node.key.type === "NGMicrosyntaxKey" + ); +} + const hasSideEffect = createTypeCheckFunction([ "CallExpression", "OptionalCallExpression", diff --git a/tests/format/angular/control-flow/__snapshots__/format.test.js.snap b/tests/format/angular/control-flow/__snapshots__/format.test.js.snap index 9aff6695f..a8a352bcd 100644 --- a/tests/format/angular/control-flow/__snapshots__/format.test.js.snap +++ b/tests/format/angular/control-flow/__snapshots__/format.test.js.snap @@ -291,6 +291,12 @@ item of
+
+ @for (item of items; let i = $index; let count = $count; track block) {} + +
+
+ =====================================output=====================================