@samitouri / QOS-React / commits / 70484844bf

[BE] switch to hermes parser for prettier (#30421)

This will allow us to parse new flow syntax since the `flow` parser is no longer updated. I had to exclude some files and have them fall back to `flow` parser since they contain invalid graphql syntax that makes the plugin crash.

Jan Kassens committed Jul 22, 2024 at 19:16 UTC 70484844bfd47382ad0011e0066ccf25d1a84464
14 files changed +104 -35
.prettierignore
+12 -1
@@ -21,11 +21,22 @@ compiler/**/__tests__/fixtures/**/*.expect.md
21 compiler/**/__tests__/fixtures/**/*.flow.js
22 compiler/**/.next
23
24 +# contains invalid graphql`...` which results in a promise rejection error from `yarn prettier-all`.
25 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-kitchensink.js
26 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.js
27 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.js
28 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-kitchensink.js
29 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-inside-logical-expression.js
30 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-logical.js
31 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.js
32 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.js
33 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/tagged-template-in-hook.js
34 +compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/tagged-template-literal.js
35 +
36 compiler/crates
37 compiler/apps/playground/public
38
39 compiler/**/LICENSE
28 -compiler/.*
40 compiler/*.md*
41 compiler/*.json
42 compiler/*.css
.prettierrc.js
+2 -1
@@ -3,12 +3,13 @@
3 const {esNextPaths} = require('./scripts/shared/pathsByLanguageVersion');
4
5 module.exports = {
6 + plugins: ['prettier-plugin-hermes-parser'],
7 bracketSpacing: false,
8 singleQuote: true,
9 bracketSameLine: true,
10 trailingComma: 'es5',
11 printWidth: 80,
11 - parser: 'flow',
12 + parser: 'hermes',
13 arrowParens: 'avoid',
14 overrides: [
15 {
compiler/apps/playground/package.json
+1 -2
@@ -33,7 +33,7 @@
33 "monaco-editor": "^0.34.1",
34 "next": "^13.5.6",
35 "notistack": "^3.0.0-alpha.7",
36 - "prettier": "3.0.3",
36 + "prettier": "^3.3.3",
37 "pretty-format": "^29.3.1",
38 "re-resizable": "^6.9.16",
39 "react": "18.2.0",
@@ -42,7 +42,6 @@
42 },
43 "devDependencies": {
44 "@types/node": "18.11.9",
45 - "@types/prettier": "^2.7.1",
45 "@types/react": "18.0.25",
46 "@types/react-dom": "18.0.9",
47 "autoprefixer": "^10.4.13",
compiler/package.json
+2 -1
@@ -38,7 +38,8 @@
38 "concurrently": "^7.4.0",
39 "folder-hash": "^4.0.4",
40 "ora": "5.4.1",
41 - "prettier": "^3.2.5",
41 + "prettier": "^3.3.3",
42 + "prettier-plugin-hermes-parser": "^0.23.0",
43 "prompt-promise": "^1.0.3",
44 "rollup": "^4.13.2",
45 "rollup-plugin-banner2": "^1.2.3",
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-noAlias.expect.md
+3 -7
@@ -37,13 +37,9 @@ function Component(props) {
37 t0 = $[1];
38 }
39 const item = t0;
40 - const x = useNoAlias(
41 - item,
42 - () => {
43 - console.log(props);
44 - },
45 - [props.a],
46 - );
40 + const x = useNoAlias(item, () => {
41 + console.log(props);
42 + }, [props.a]);
43 let t1;
44 if ($[2] !== x || $[3] !== item) {
45 t1 = [x, item];
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-constant-prop.expect.md
+2 -2
@@ -47,7 +47,7 @@ function useFoo(cond) {
47 t0 = t1;
48 const derived1 = t0;
49
50 - const derived2 = cond ?? Math.min(0, 1) ? 1 : 2;
50 + const derived2 = (cond ?? Math.min(0, 1)) ? 1 : 2;
51 let t2;
52 let t3;
53 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
@@ -59,7 +59,7 @@ function useFoo(cond) {
59 t2 = t3;
60 const derived3 = t2;
61
62 - const derived4 = Math.min(0, -1) ?? cond ? 1 : 2;
62 + const derived4 = (Math.min(0, -1) ?? cond) ? 1 : 2;
63 let t4;
64 if ($[2] !== derived2 || $[3] !== derived4) {
65 t4 = [derived1, derived2, derived3, derived4];
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ternary-expression.expect.md
+2 -2
@@ -3,7 +3,7 @@
3
4 ```javascript
5 function ternary(props) {
6 - const a = props.a && props.b ? props.c || props.d : (props.e ?? props.f);
6 + const a = props.a && props.b ? props.c || props.d : props.e ?? props.f;
7 const b = props.a ? (props.b && props.c ? props.d : props.e) : props.f;
8 return a ? b : null;
9 }
@@ -20,7 +20,7 @@ export const FIXTURE_ENTRYPOINT = {
20
21 ```javascript
22 function ternary(props) {
23 - const a = props.a && props.b ? props.c || props.d : props.e ?? props.f;
23 + const a = props.a && props.b ? props.c || props.d : (props.e ?? props.f);
24 const b = props.a ? (props.b && props.c ? props.d : props.e) : props.f;
25 return a ? b : null;
26 }
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ternary-expression.js
+1 -1
@@ -1,5 +1,5 @@
1 function ternary(props) {
2 - const a = props.a && props.b ? props.c || props.d : (props.e ?? props.f);
2 + const a = props.a && props.b ? props.c || props.d : props.e ?? props.f;
3 const b = props.a ? (props.b && props.c ? props.d : props.e) : props.f;
4 return a ? b : null;
5 }
compiler/yarn.lock
+52 -16
@@ -3144,11 +3144,6 @@
3144 resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.0.tgz#ea03e9f0376a4446f44797ca19d9c46c36e352dc"
3145 integrity sha512-RI1L7N4JnW5gQw2spvL7Sllfuf1SaHdrZpCHiBlCXjIlufi1SMNnbu2teze3/QE67Fg2tBlH7W+mi4hVNk4p0A==
3146
3147 -"@types/prettier@^2.7.1":
3148 - version "2.7.3"
3149 - resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.3.tgz#3e51a17e291d01d17d3fc61422015a933af7a08f"
3150 - integrity sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==
3151 -
3147 "@types/prop-types@*":
3148 version "15.7.5"
3149 resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
@@ -5812,6 +5807,11 @@ hermes-estree@0.22.0:
5807 resolved "https://registry.yarnpkg.com/hermes-estree/-/hermes-estree-0.22.0.tgz#38559502b119f728901d2cfe2ef422f277802a1d"
5808 integrity sha512-FLBt5X9OfA8BERUdc6aZS36Xz3rRuB0Y/mfocSADWEJfomc1xfene33GdyAmtTkKTBXTN/EgAy+rjTKkkZJHlw==
5809
5810 +hermes-estree@0.23.0:
5811 + version "0.23.0"
5812 + resolved "https://registry.yarnpkg.com/hermes-estree/-/hermes-estree-0.23.0.tgz#89c5419877b9d6bce4bb616821f496f5c5daddbc"
5813 + integrity sha512-Rkp0PNLGpORw4ktsttkVbpYJbrYKS3hAnkxu8D9nvQi6LvSbuPa+tYw/t2u3Gjc35lYd/k95YkjqyTcN4zspag==
5814 +
5815 hermes-parser@0.14.0:
5816 version "0.14.0"
5817 resolved "https://registry.yarnpkg.com/hermes-parser/-/hermes-parser-0.14.0.tgz#edb2e7172fce996d2c8bbba250d140b70cc1aaaf"
@@ -5833,6 +5833,13 @@ hermes-parser@0.17.1:
5833 dependencies:
5834 hermes-estree "0.17.1"
5835
5836 +hermes-parser@0.23.0:
5837 + version "0.23.0"
5838 + resolved "https://registry.yarnpkg.com/hermes-parser/-/hermes-parser-0.23.0.tgz#3541907b77ca9e94fd093e8ef0ff97ca5340dee8"
5839 + integrity sha512-xLwM4ylfHGwrm+2qXfO1JT/fnqEDGSnpS/9hQ4VLtqTexSviu2ZpBgz07U8jVtndq67qdb/ps0qvaWDZ3fkTyg==
5840 + dependencies:
5841 + hermes-estree "0.23.0"
5842 +
5843 hermes-parser@^0.19.1:
5844 version "0.19.2"
5845 resolved "https://registry.yarnpkg.com/hermes-parser/-/hermes-parser-0.19.2.tgz#67b0fd92f4d7a374234f58c4f980f816734a7695"
@@ -8469,15 +8476,19 @@ prelude-ls@~1.1.2:
8476 resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
8477 integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==
8478
8472 -prettier@*, prettier@^3.2.5:
8473 - version "3.2.5"
8474 - resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
8475 - integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==
8479 +prettier-plugin-hermes-parser@0.23.0, prettier-plugin-hermes-parser@^0.23.0:
8480 + version "0.23.0"
8481 + resolved "https://registry.yarnpkg.com/prettier-plugin-hermes-parser/-/prettier-plugin-hermes-parser-0.23.0.tgz#67fa061e503600087169283e150bc3f3239bf39c"
8482 + integrity sha512-EMwgZFcKDyVfUCvIy/kxVc4siYEOYPt7lLqtaELVadKYNbOLUFjYW3QKGZ8jzidUy4DonfFbi/hJOXJ5vfRzxA==
8483 + dependencies:
8484 + hermes-estree "0.23.0"
8485 + hermes-parser "0.23.0"
8486 + prettier-plugin-hermes-parser "0.23.0"
8487
8477 -prettier@3.0.3:
8478 - version "3.0.3"
8479 - resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.3.tgz#432a51f7ba422d1469096c0fdc28e235db8f9643"
8480 - integrity sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==
8488 +prettier@*, prettier@^3.3.3:
8489 + version "3.3.3"
8490 + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.3.tgz#30c54fe0be0d8d12e6ae61dbb10109ea00d53105"
8491 + integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==
8492
8493 pretty-format@^24:
8494 version "24.9.0"
@@ -9173,7 +9184,16 @@ string-length@^4.0.1:
9184 char-regex "^1.0.2"
9185 strip-ansi "^6.0.0"
9186
9176 -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
9187 +"string-width-cjs@npm:string-width@^4.2.0":
9188 + version "4.2.3"
9189 + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
9190 + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
9191 + dependencies:
9192 + emoji-regex "^8.0.0"
9193 + is-fullwidth-code-point "^3.0.0"
9194 + strip-ansi "^6.0.1"
9195 +
9196 +string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
9197 version "4.2.3"
9198 resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
9199 integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -9266,7 +9286,14 @@ string_decoder@^1.1.1:
9286 dependencies:
9287 safe-buffer "~5.2.0"
9288
9269 -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
9289 +"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
9290 + version "6.0.1"
9291 + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
9292 + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
9293 + dependencies:
9294 + ansi-regex "^5.0.1"
9295 +
9296 +strip-ansi@^6.0.0, strip-ansi@^6.0.1:
9297 version "6.0.1"
9298 resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
9299 integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -9917,7 +9944,7 @@ wordwrap@>=0.0.2:
9944 resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
9945 integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
9946
9920 -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
9947 +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
9948 version "7.0.0"
9949 resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
9950 integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -9935,6 +9962,15 @@ wrap-ansi@^6.2.0:
9962 string-width "^4.1.0"
9963 strip-ansi "^6.0.0"
9964
9965 +wrap-ansi@^7.0.0:
9966 + version "7.0.0"
9967 + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
9968 + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
9969 + dependencies:
9970 + ansi-styles "^4.0.0"
9971 + string-width "^4.1.0"
9972 + strip-ansi "^6.0.0"
9973 +
9974 wrap-ansi@^8.1.0:
9975 version "8.1.0"
9976 resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
package.json
+1
@@ -82,6 +82,7 @@
82 "ncp": "^2.0.0",
83 "prettier": "^3.3.3",
84 "prettier-2": "npm:prettier@^2",
85 + "prettier-plugin-hermes-parser": "^0.23.0",
86 "pretty-format": "^29.4.1",
87 "prop-types": "^15.6.2",
88 "random-seed": "^0.3.0",
packages/react-devtools-shared/src/hooks/astUtils.js
+1 -1
@@ -289,7 +289,7 @@ function getHookVariableName(
289 const nodeType = hook.node.id.type;
290 switch (nodeType) {
291 case AST_NODE_TYPES.ARRAY_PATTERN:
292 - return !isCustomHook ? (hook.node.id.elements[0]?.name ?? null) : null;
292 + return !isCustomHook ? hook.node.id.elements[0]?.name ?? null : null;
293
294 case AST_NODE_TYPES.IDENTIFIER:
295 return hook.node.id.name;
packages/react-noop-renderer/src/createReactNoop.js
+1 -1
@@ -245,7 +245,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
245 id: instance.id,
246 type: type,
247 parent: instance.parent,
248 - children: keepChildren ? instance.children : (children ?? []),
248 + children: keepChildren ? instance.children : children ?? [],
249 text: shouldSetTextContent(type, newProps)
250 ? computeText((newProps.children: any) + '', instance.context)
251 : null,
scripts/flow/config/flowconfig
+3
@@ -14,6 +14,9 @@
14 .*/__mocks__/.*
15 .*/__tests__/.*
16
17 +# contains modern flow syntax that requires a Flow upgrade
18 +.*/node_modules/prettier-plugin-hermes-parser/.*
19 +
20 # TODO: noop should get its own inlinedHostConfig entry
21 .*/packages/react-noop-renderer/.*
22
yarn.lock
+21
@@ -9133,6 +9133,11 @@ hermes-estree@0.22.0:
9133 resolved "https://registry.yarnpkg.com/hermes-estree/-/hermes-estree-0.22.0.tgz#38559502b119f728901d2cfe2ef422f277802a1d"
9134 integrity sha512-FLBt5X9OfA8BERUdc6aZS36Xz3rRuB0Y/mfocSADWEJfomc1xfene33GdyAmtTkKTBXTN/EgAy+rjTKkkZJHlw==
9135
9136 +hermes-estree@0.23.0:
9137 + version "0.23.0"
9138 + resolved "https://registry.yarnpkg.com/hermes-estree/-/hermes-estree-0.23.0.tgz#89c5419877b9d6bce4bb616821f496f5c5daddbc"
9139 + integrity sha512-Rkp0PNLGpORw4ktsttkVbpYJbrYKS3hAnkxu8D9nvQi6LvSbuPa+tYw/t2u3Gjc35lYd/k95YkjqyTcN4zspag==
9140 +
9141 hermes-parser@0.22.0, hermes-parser@^0.22.0:
9142 version "0.22.0"
9143 resolved "https://registry.yarnpkg.com/hermes-parser/-/hermes-parser-0.22.0.tgz#fc8e0e6c7bfa8db85b04c9f9544a102c4fcb4040"
@@ -9140,6 +9145,13 @@ hermes-parser@0.22.0, hermes-parser@^0.22.0:
9145 dependencies:
9146 hermes-estree "0.22.0"
9147
9148 +hermes-parser@0.23.0:
9149 + version "0.23.0"
9150 + resolved "https://registry.yarnpkg.com/hermes-parser/-/hermes-parser-0.23.0.tgz#3541907b77ca9e94fd093e8ef0ff97ca5340dee8"
9151 + integrity sha512-xLwM4ylfHGwrm+2qXfO1JT/fnqEDGSnpS/9hQ4VLtqTexSviu2ZpBgz07U8jVtndq67qdb/ps0qvaWDZ3fkTyg==
9152 + dependencies:
9153 + hermes-estree "0.23.0"
9154 +
9155 homedir-polyfill@^1.0.0, homedir-polyfill@^1.0.1:
9156 version "1.0.3"
9157 resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz#743298cef4e5af3e194161fbadcc2151d3a058e8"
@@ -13268,6 +13280,15 @@ prepend-http@^2.0.0:
13280 resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
13281 integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
13282
13283 +prettier-plugin-hermes-parser@0.23.0, prettier-plugin-hermes-parser@^0.23.0:
13284 + version "0.23.0"
13285 + resolved "https://registry.yarnpkg.com/prettier-plugin-hermes-parser/-/prettier-plugin-hermes-parser-0.23.0.tgz#67fa061e503600087169283e150bc3f3239bf39c"
13286 + integrity sha512-EMwgZFcKDyVfUCvIy/kxVc4siYEOYPt7lLqtaELVadKYNbOLUFjYW3QKGZ8jzidUy4DonfFbi/hJOXJ5vfRzxA==
13287 + dependencies:
13288 + hermes-estree "0.23.0"
13289 + hermes-parser "0.23.0"
13290 + prettier-plugin-hermes-parser "0.23.0"
13291 +
13292 prettier@*, prettier@^3.3.3:
13293 version "3.3.3"
13294 resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.3.tgz#30c54fe0be0d8d12e6ae61dbb10109ea00d53105"