Skip to content

Commit 96bbaed

Browse files
committed
Support Angular v21.2 (#18722)
1 parent 881360b commit 96bbaed

9 files changed

Lines changed: 230 additions & 14 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#### Support Angular v21.2 (#18722, #19034 by @fisker)
2+
3+
Exhaustive typechecking with `@default never;`
4+
5+
<!-- prettier-ignore -->
6+
```html
7+
<!-- Input -->
8+
@switch (foo) {
9+
@case (1) {}
10+
@default never;
11+
}
12+
13+
<!-- Prettier stable -->
14+
SyntaxError: Incomplete block "default never". If you meant to write the @ character, you should use the "&#64;" HTML entity instead. (3:3)
15+
16+
<!-- Prettier main -->
17+
@switch (foo) {
18+
@case (1) {}
19+
@default never;
20+
}
21+
```
22+
23+
`arrow function` and `instanceof` expressions.
24+
25+
<!-- prettier-ignore -->
26+
```html
27+
<!-- Input -->
28+
@let fn = (a) => a? 1:2;
29+
30+
{{ fn ( a instanceof b)}}
31+
32+
<!-- Prettier stable -->
33+
@let fn = (a) => a? 1:2;
34+
35+
{{ fn ( a instanceof b)}}
36+
37+
<!-- Prettier main -->
38+
@let fn = (a) => (a ? 1 : 2);
39+
40+
{{ fn(a instanceof b) }}
41+
```

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"bin"
4343
],
4444
"dependencies": {
45-
"@angular/compiler": "21.1.0",
45+
"@angular/compiler": "21.2.8",
4646
"@babel/code-frame": "8.0.0-beta.3",
4747
"@babel/parser": "8.0.0-beta.3",
4848
"@babel/types": "8.0.0-beta.3",
@@ -55,7 +55,7 @@
5555
"@typescript-eslint/visitor-keys": "8.48.0",
5656
"acorn": "8.15.0",
5757
"acorn-jsx": "5.3.2",
58-
"angular-estree-parser": "15.3.0",
58+
"angular-estree-parser": "15.4.3",
5959
"angular-html-parser": "10.5.0",
6060
"camelcase": "9.0.0",
6161
"ci-info": "4.3.1",

src/language-js/print/function-parameters.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ function printFunctionParameters(
157157
"(",
158158
indent([softline, ...printed]),
159159
ifBreak(
160-
!hasRestParameter(functionNode) && shouldPrintComma(options, "all")
160+
!hasRestParameter(functionNode) &&
161+
shouldPrintComma(options, "all") &&
162+
// Angular does not allow trailing comma
163+
path.root.type !== "NGRoot"
161164
? ","
162165
: "",
163166
),

tests/format/angular/expression/__snapshots__/format.test.js.snap

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,63 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3+
exports[`arrow-function.html format 1`] = `
4+
====================================options=====================================
5+
parsers: ["angular"]
6+
printWidth: 80 (default) |
7+
=====================================input======================================
8+
@let fn = (a, b) => componentValue + a + b;
9+
One: {{fn(0, 1)}}
10+
11+
@if (true) {
12+
Two: {{fn(1, 1)}}
13+
14+
<button (click)=" componentValue = fn(2, 1)"></button>
15+
<button (click)=" componentValue => fn(2, 1)"></button>
16+
}
17+
18+
19+
{{[(a) => a + 1][0](1000)}}
20+
{{[(a ) => a + 1 + componentProp][0](1000)}}
21+
22+
23+
@let a = 1;
24+
25+
@if (true) {
26+
@let b = 2;
27+
28+
@if (true) {
29+
@let c = 3;
30+
{{(() => a + b + c)()}}
31+
}
32+
}
33+
34+
=====================================output=====================================
35+
@let fn = (a, b) => componentValue + a + b; One: {{ fn(0, 1) }}
36+
37+
@if (true) {
38+
Two: {{ fn(1, 1) }}
39+
40+
<button (click)="componentValue = fn(2, 1)"></button>
41+
<button (click)="(componentValue) => fn(2, 1)"></button>
42+
}
43+
44+
{{ [(a) => a + 1][0](1000) }}
45+
{{ [(a) => a + 1 + componentProp][0](1000) }}
46+
47+
@let a = 1;
48+
49+
@if (true) {
50+
@let b = 2;
51+
52+
@if (true) {
53+
@let c = 3;
54+
{{ (() => a + b + c)() }}
55+
}
56+
}
57+
58+
================================================================================
59+
`;
60+
361
exports[`exponentiation-operators.html format 1`] = `
462
====================================options=====================================
563
parsers: ["angular"]
@@ -33,6 +91,22 @@ printWidth: 80
3391
================================================================================
3492
`;
3593
94+
exports[`instanceof-operator.html format 1`] = `
95+
====================================options=====================================
96+
parsers: ["angular"]
97+
printWidth: 80 (default) |
98+
=====================================input======================================
99+
{{
100+
101+
( (a instanceof (b)))
102+
}}
103+
104+
=====================================output=====================================
105+
{{ a instanceof b }}
106+
107+
================================================================================
108+
`;
109+
36110
exports[`spread-element.html format 1`] = `
37111
====================================options=====================================
38112
parsers: ["angular"]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`snippet: #0 - {"arrowParens":"avoid"} format 1`] = `
4+
====================================options=====================================
5+
arrowParens: "avoid"
6+
parsers: ["angular"]
7+
printWidth: 80 (default) |
8+
=====================================input======================================
9+
@let fn = ( oneArgument) => 1;
10+
=====================================output=====================================
11+
@let fn = oneArgument => 1;
12+
13+
================================================================================
14+
`;
15+
16+
exports[`snippet: #0 - {"printWidth":1,"trailingComma":"all"} format 1`] = `
17+
====================================options=====================================
18+
parsers: ["angular"]
19+
printWidth: 1
20+
trailingComma: "all"
21+
| printWidth: 1
22+
=====================================input======================================
23+
@let fn = ( should, not, print,trailing, comma) => 1;
24+
=====================================output=====================================
25+
@let fn =
26+
(
27+
should,
28+
not,
29+
print,
30+
trailing,
31+
comma
32+
) =>
33+
1;
34+
35+
================================================================================
36+
`;
37+
38+
exports[`snippet: #1 - {"arrowParens":"avoid"} format 1`] = `
39+
====================================options=====================================
40+
arrowParens: "avoid"
41+
parsers: ["angular"]
42+
printWidth: 80 (default) |
43+
=====================================input======================================
44+
@let fn = oneArgument => 1;
45+
=====================================output=====================================
46+
@let fn = oneArgument => 1;
47+
48+
================================================================================
49+
`;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
runFormatTest(
2+
{
3+
importMeta: import.meta,
4+
snippets: ["@let fn = ( should, not, print,trailing, comma) => 1;"],
5+
},
6+
["angular"],
7+
{ printWidth: 1, trailingComma: "all" },
8+
);
9+
10+
runFormatTest(
11+
{
12+
importMeta: import.meta,
13+
snippets: [
14+
"@let fn = ( oneArgument) => 1;",
15+
"@let fn = oneArgument => 1;",
16+
],
17+
},
18+
["angular"],
19+
{ arrowParens: "avoid" },
20+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@let fn = (a, b) => componentValue + a + b;
2+
One: {{fn(0, 1)}}
3+
4+
@if (true) {
5+
Two: {{fn(1, 1)}}
6+
7+
<button (click)=" componentValue = fn(2, 1)"></button>
8+
<button (click)=" componentValue => fn(2, 1)"></button>
9+
}
10+
11+
12+
{{[(a) => a + 1][0](1000)}}
13+
{{[(a ) => a + 1 + componentProp][0](1000)}}
14+
15+
16+
@let a = 1;
17+
18+
@if (true) {
19+
@let b = 2;
20+
21+
@if (true) {
22+
@let c = 3;
23+
{{(() => a + b + c)()}}
24+
}
25+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{
2+
3+
( (a instanceof (b)))
4+
}}

yarn.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ __metadata:
55
version: 8
66
cacheKey: 10
77

8-
"@angular/compiler@npm:21.1.0":
9-
version: 21.1.0
10-
resolution: "@angular/compiler@npm:21.1.0"
8+
"@angular/compiler@npm:21.2.8":
9+
version: 21.2.8
10+
resolution: "@angular/compiler@npm:21.2.8"
1111
dependencies:
1212
tslib: "npm:^2.3.0"
13-
checksum: 10/1f409c20eb36079719e004f9e683a41d9d9fd975d814132faa28f941a0d491ba392c7cca92061f8dbe540bd922cac905f76ccab48a87c82c764b3b7cdb6b28dd
13+
checksum: 10/5bcf866cf01fbc19b016df4c77aa662440ba5ea3b1615ea21b6c69cd52c5b6cf55fbf8003ee8bcfd9199deac7d33a37ccbf4b9feb4bcc21e65cae388d2fa6a88
1414
languageName: node
1515
linkType: hard
1616

@@ -2852,12 +2852,12 @@ __metadata:
28522852
languageName: node
28532853
linkType: hard
28542854

2855-
"angular-estree-parser@npm:15.3.0":
2856-
version: 15.3.0
2857-
resolution: "angular-estree-parser@npm:15.3.0"
2855+
"angular-estree-parser@npm:15.4.3":
2856+
version: 15.4.3
2857+
resolution: "angular-estree-parser@npm:15.4.3"
28582858
peerDependencies:
2859-
"@angular/compiler": ">=21.0.7 || >= 21.1.0-0"
2860-
checksum: 10/9266d6bf73fac7f2d96e6a7b306bef0a6b6563f4f11a36aa308d4ca2fda2868839c8831c2e95d5ea008636e061c1cdc0668c01fc9f9876eb1b5f6846217fc2ec
2859+
"@angular/compiler": ">=21.0.7 || >= 21.2.0-0"
2860+
checksum: 10/a31569c99bb89e20564c0caa77c8db28070170bbbb145fd5afdda77a0d535af71cd3bd13d1d25bd6fe6cffa81ae6ab57f37cd1a9ea1dcdb5039ac419945515ce
28612861
languageName: node
28622862
linkType: hard
28632863

@@ -7496,7 +7496,7 @@ __metadata:
74967496
version: 0.0.0-use.local
74977497
resolution: "prettier@workspace:."
74987498
dependencies:
7499-
"@angular/compiler": "npm:21.1.0"
7499+
"@angular/compiler": "npm:21.2.8"
75007500
"@babel/code-frame": "npm:8.0.0-beta.3"
75017501
"@babel/generator": "npm:8.0.0-beta.3"
75027502
"@babel/parser": "npm:8.0.0-beta.3"
@@ -7517,7 +7517,7 @@ __metadata:
75177517
"@typescript-eslint/visitor-keys": "npm:8.48.0"
75187518
acorn: "npm:8.15.0"
75197519
acorn-jsx: "npm:5.3.2"
7520-
angular-estree-parser: "npm:15.3.0"
7520+
angular-estree-parser: "npm:15.4.3"
75217521
angular-html-parser: "npm:10.5.0"
75227522
base64-arraybuffer-es6: "npm:3.1.0"
75237523
browserslist: "npm:4.28.0"

0 commit comments

Comments
 (0)