diff --git a/src/language-js/print/angular.js b/src/language-js/print/angular.js index df014d74f..e2863ed51 100644 --- a/src/language-js/print/angular.js +++ b/src/language-js/print/angular.js @@ -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"), diff --git a/tests/format/angular/control-flow/__snapshots__/jsfmt.spec.js.snap b/tests/format/angular/control-flow/__snapshots__/jsfmt.spec.js.snap index d94db9bc4..d9f9c0daa 100644 --- a/tests/format/angular/control-flow/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/angular/control-flow/__snapshots__/jsfmt.spec.js.snap @@ -278,6 +278,13 @@ item of emptyCollection; track item.id; "> +
+ @for ( item of items; track item){ + } + +
+
+ =====================================output===================================== -
  • +
  • + +
    + @for (item of items; track item) {} + +
    +
    ================================================================================ `; diff --git a/tests/format/angular/control-flow/for.html b/tests/format/angular/control-flow/for.html index 202387c04..343812adc 100644 --- a/tests/format/angular/control-flow/for.html +++ b/tests/format/angular/control-flow/for.html @@ -45,3 +45,10 @@ i; item of emptyCollection; track item.id; "> + +
    + @for ( item of items; track item){ + } + +
    +