Skip to content

Commit

Permalink
Update @angular/compiler to v14 (prettier#13609)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and medikoo committed Feb 5, 2024
1 parent 2e94c93 commit 1e1ab1a
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 41 deletions.
28 changes: 28 additions & 0 deletions changelog_unreleased/angular/13609.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#### Update `@angular/compiler` to v14 (#13609 by @fisker)

- Support shorthand object
- [Drop support for quote expressions](https://github.com/angular/angular/pull/44915)

<!-- prettier-ignore -->
```html
<!-- Input -->
<div [input]="{a, b : 2 }"></div>

<!-- Prettier stable -->
Error: Cannot find front char /:/ from index 0 in "{a, b : 2 }"

<!-- Prettier main -->
<div [input]="{ a, b: 2 }"></div>
```

<!-- prettier-ignore -->
```html
<!-- Input -->
<a [href]="http://google.com">Click me</a>

<!-- Prettier stable -->
<a [href]="http: //google.com">Click me</a>

<!-- Prettier main -->
<div [href]="http://google.com"></div>
```
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"execa",
"fbglyph",
"fdescribe",
"fesm",
"Ficarra",
"Filipe",
"Fiorini",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"bin"
],
"dependencies": {
"@angular/compiler": "12.2.16",
"@angular/compiler": "14.2.5",
"@babel/code-frame": "7.18.6",
"@babel/parser": "7.21.3",
"@babel/types": "7.20.0",
Expand All @@ -40,7 +40,7 @@
"@typescript-eslint/visitor-keys": "5.45.0",
"acorn": "8.8.1",
"acorn-jsx": "5.3.2",
"angular-estree-parser": "3.0.3",
"angular-estree-parser": "4.0.1",
"angular-html-parser": "2.0.0",
"camelcase": "7.0.0",
"chalk": "5.0.1",
Expand Down
35 changes: 27 additions & 8 deletions scripts/build/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,33 @@ const pluginFiles = [
"src/language-js/parse/meriyah.js",
{
input: "src/language-js/parse/angular.js",
replaceModule: ["ast.js", "lexer.js", "parser.js"].map((file) => ({
module: require.resolve(
`@angular/compiler/src/expression_parser/${file}`
),
path: require.resolve(
`@angular/compiler/esm2015/src/expression_parser/${file}`
),
})),
replaceModule: [
// We only use a small set of `@angular/compiler` from `esm2020/src/expression_parser/`
// Those files can't be imported, they also not directly runnable, because `.mjs` extension is missing
{
module: path.join(
path.dirname(require.resolve("@angular/compiler/package.json")),
"fesm2020/compiler.mjs"
),
text: /* indent */ `
export * from '../esm2020/src/expression_parser/ast.mjs';
export {Lexer} from '../esm2020/src/expression_parser/lexer.mjs';
export {Parser} from '../esm2020/src/expression_parser/parser.mjs';
`,
},
...[
"expression_parser/lexer.mjs",
"expression_parser/parser.mjs",
"ml_parser/interpolation_config.mjs",
].map((file) => ({
module: path.join(
path.dirname(require.resolve("@angular/compiler/package.json")),
`esm2020/src/${file}`
),
process: (text) =>
text.replaceAll(/(?<=import .*? from )'(.{1,2}\/.*)'/g, "'$1.mjs'"),
})),
],
},
{
input: "src/language-css/parser-postcss.js",
Expand Down
2 changes: 0 additions & 2 deletions src/language-js/print/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ function printAngular(path, options, print) {
);
case "NGEmptyExpression":
return "";
case "NGQuotedExpression":
return [node.prefix, ": ", node.value.trim()];
case "NGMicrosyntax":
return path.map(
(childPath, index) => [
Expand Down
1 change: 0 additions & 1 deletion src/language-js/traverse/visitor-keys.evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const angularVisitorKeys = {
NGPipeExpression: ["left", "right", "arguments"],
NGChainedExpression: ["expressions"],
NGEmptyExpression: [],
NGQuotedExpression: [],
NGMicrosyntax: ["body"],
NGMicrosyntaxKey: [],
NGMicrosyntaxExpression: ["expression", "alias"],
Expand Down
12 changes: 5 additions & 7 deletions tests/format/angular/angular/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ printWidth: 80
[target]="a"
[target]="a // hello"
[target]="a.b"
[target]="javascript: 'hello world'"
[target]=" javascript : 'hello world' "
[target]="a?.b()"
[target]="a?.b"
[target]="this.a"
Expand Down Expand Up @@ -733,7 +733,7 @@ printWidth: 80
[target]="a"
[target]="a // hello"
[target]="a.b"
[target]="javascript: 'hello world'"
[target]=" javascript : 'hello world' "
[target]="a?.b()"
[target]="a?.b"
[target]="this.a"
Expand Down Expand Up @@ -1084,9 +1084,7 @@ printWidth: 1
[target]="
a.b
"
[target]="
javascript: 'hello world'
"
[target]=" javascript : 'hello world' "
[target]="
a?.b()
"
Expand Down Expand Up @@ -1602,7 +1600,7 @@ trailingComma: "es5"
[target]="a"
[target]="a // hello"
[target]="a.b"
[target]="javascript: 'hello world'"
[target]=" javascript : 'hello world' "
[target]="a?.b()"
[target]="a?.b"
[target]="this.a"
Expand Down Expand Up @@ -1871,7 +1869,7 @@ trailingComma: "none"
[target]="a"
[target]="a // hello"
[target]="a.b"
[target]="javascript: 'hello world'"
[target]=" javascript : 'hello world' "
[target]="a?.b()"
[target]="a?.b"
[target]="this.a"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ printWidth: 80
| printWidth
=====================================input======================================
<ng-container *ngTemplateOutlet="someTmpl; context: {app}"></ng-container>
<div dir [input]="{ a, b: 2 }"></div>
=====================================output=====================================
<ng-container *ngTemplateOutlet="someTmpl; context: { app }"></ng-container>
<div dir [input]="{ a, b: 2 }"></div>
================================================================================
`;
1 change: 1 addition & 0 deletions tests/format/angular/shorthand/basic.html
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<ng-container *ngTemplateOutlet="someTmpl; context: {app}"></ng-container>
<div dir [input]="{ a, b: 2 }"></div>
1 change: 0 additions & 1 deletion tests/unit/__snapshots__/visitor-keys.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ exports[`visitor keys estree 1`] = `
"right",
"arguments",
],
"NGQuotedExpression": [],
"NGRoot": [
"node",
],
Expand Down
38 changes: 18 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ __metadata:
languageName: node
linkType: hard

"@angular/compiler@npm:12.2.16":
version: 12.2.16
resolution: "@angular/compiler@npm:12.2.16"
"@angular/compiler@npm:14.2.5":
version: 14.2.5
resolution: "@angular/compiler@npm:14.2.5"
dependencies:
tslib: ^2.2.0
checksum: 87e4d5df658c73c5ed25269c72f8797a006213a98ce13607377205d5faa7dbc204ca8127d589c1c4848ab8616b4aa58005b29eb76da16a34f635e054d679ff69
tslib: ^2.3.0
peerDependencies:
"@angular/core": 14.2.5
peerDependenciesMeta:
"@angular/core":
optional: true
checksum: 665718c8384a7bd7aa150342658775afac2375ba41fa896fba74bee2f0ca29173ce3dfba2cce6aa483d486afa968235f4b1c8647050740bf74aaeb3fb89f1e42
languageName: node
linkType: hard

Expand Down Expand Up @@ -2354,15 +2359,15 @@ __metadata:
languageName: node
linkType: hard

"angular-estree-parser@npm:3.0.3":
version: 3.0.3
resolution: "angular-estree-parser@npm:3.0.3"
"angular-estree-parser@npm:4.0.1":
version: 4.0.1
resolution: "angular-estree-parser@npm:4.0.1"
dependencies:
lines-and-columns: ^2.0.3
tslib: ^2.4.0
peerDependencies:
"@angular/compiler": ^9.1.0 || ^10.0.0 || ^11.0.0 || ^12.0.0
checksum: bdcadb3e9cde9bfbfc826bfaca8d30c218c45f00c3271f33484a0bc8c05e86d2ce91e84c1eca7ef289a57a350e16f5ab0ffcb508ec2825a9339d0ccc9d37ccaf
"@angular/compiler": ^14.0.0
checksum: b04a8b8fee56811c5d3b58a7fb13c3cf8a623203cde6a393633e1e2f0605770a90cc8b9b20ef242d6e99de3d47e0314a9bf0247c0c74b7ebb1b0b6ef94c2cabc
languageName: node
linkType: hard

Expand Down Expand Up @@ -7718,7 +7723,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "prettier-elastic@workspace:."
dependencies:
"@angular/compiler": 12.2.16
"@angular/compiler": 14.2.5
"@babel/code-frame": 7.18.6
"@babel/generator": 7.19.0
"@babel/parser": 7.21.3
Expand All @@ -7737,7 +7742,7 @@ __metadata:
"@typescript-eslint/visitor-keys": 5.45.0
acorn: 8.8.1
acorn-jsx: 5.3.2
angular-estree-parser: 3.0.3
angular-estree-parser: 4.0.1
angular-html-parser: 2.0.0
benchmark: 2.1.4
browserslist-to-esbuild: 1.2.0
Expand Down Expand Up @@ -9142,14 +9147,7 @@ __metadata:
languageName: node
linkType: hard

"tslib@npm:^2.2.0":
version: 2.4.1
resolution: "tslib@npm:2.4.1"
checksum: 19480d6e0313292bd6505d4efe096a6b31c70e21cf08b5febf4da62e95c265c8f571f7b36fcc3d1a17e068032f59c269fab3459d6cd3ed6949eafecf64315fca
languageName: node
linkType: hard

"tslib@npm:^2.4.0":
"tslib@npm:^2.3.0, tslib@npm:^2.4.0":
version: 2.6.2
resolution: "tslib@npm:2.6.2"
checksum: 329ea56123005922f39642318e3d1f0f8265d1e7fcb92c633e0809521da75eeaca28d2cf96d7248229deb40e5c19adf408259f4b9640afd20d13aecc1430f3ad
Expand Down

0 comments on commit 1e1ab1a

Please sign in to comment.