fix: do not format computed template which could be unexpected (#15972)

This commit is contained in:
JounQin authored and GitHub committed 2024-01-23 10:36:15 +09:00
1 parent 91a2e2513e
commit 678de0289c
4 files changed
+97

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
#### Unexpected embedded formatting for Angular template (#15969 by @JounQin)
Computed template should not be considered as Angular component template
<!-- prettier-ignore -->
```ts
// Input
const template = "foobar";
@Component({
[template]: `<h1>{{ hello }}</h1>`,
})
export class AppComponent {}
// Prettier stable
const template = "foobar";
@Component({
[template]: `<h1>{{ hello }}</h1>`,
})
export class AppComponent {}
// Prettier main
const template = "foobar";
@Component({
[template]: `<h1>{{ hello }}</h1>`,
})
export class AppComponent {}
```
+1
View File
@@ -56,6 +56,7 @@ function isAngularComponentTemplate(path) {
(node) => node.type === "TemplateLiteral",
(node, name) =>
isObjectProperty(node) &&
!node.computed &&
node.key.type === "Identifier" &&
node.key.name === "template" &&
name === "value",
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';
const template = "foobar";
@Component({
[template]: `<h1>{{ hello }}</h1>`,
})
export class AppComponent {}
@@ -156,6 +156,64 @@ export class AppComponent {}
================================================================================
`;
exports[`15969-computed.component.ts - {"trailingComma":"es5"} format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "es5"
| printWidth
=====================================input======================================
import { Component } from '@angular/core';
const template = "foobar";
@Component({
[template]: \`<h1>{{ hello }}</h1>\`,
})
export class AppComponent {}
=====================================output=====================================
import { Component } from "@angular/core";
const template = "foobar";
@Component({
[template]: \`<h1>{{ hello }}</h1>\`,
})
export class AppComponent {}
================================================================================
`;
exports[`15969-computed.component.ts - {"trailingComma":"none"} format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "none"
| printWidth
=====================================input======================================
import { Component } from '@angular/core';
const template = "foobar";
@Component({
[template]: \`<h1>{{ hello }}</h1>\`,
})
export class AppComponent {}
=====================================output=====================================
import { Component } from "@angular/core";
const template = "foobar";
@Component({
[template]: \`<h1>{{ hello }}</h1>\`
})
export class AppComponent {}
================================================================================
`;
exports[`test.component.ts - {"trailingComma":"es5"} format 1`] = `
====================================options=====================================
parsers: ["typescript"]