From 5bc21dbcf0a2ea2b2fb2a33d21b003ed3c645428 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Thu, 16 May 2024 12:49:28 +0200 Subject: [PATCH 01/11] feat: add eslint rule --- .eslintrc.js | 5 +- package-lock.json | 170 ++++++++++++------ package.json | 1 + ...+0.0.0-experimental-53bb89e-20240515.patch | 13 ++ 4 files changed, 129 insertions(+), 60 deletions(-) create mode 100644 patches/eslint-plugin-react-compiler+0.0.0-experimental-53bb89e-20240515.patch diff --git a/.eslintrc.js b/.eslintrc.js index a4810ddcebcc..569cf6b6ee04 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -95,7 +95,7 @@ module.exports = { 'plugin:you-dont-need-lodash-underscore/all', 'prettier', ], - plugins: ['@typescript-eslint', 'jsdoc', 'you-dont-need-lodash-underscore', 'react-native-a11y', 'react', 'testing-library'], + plugins: ['@typescript-eslint', 'jsdoc', 'you-dont-need-lodash-underscore', 'react-native-a11y', 'react', 'testing-library', 'eslint-plugin-react-compiler'], parser: '@typescript-eslint/parser', parserOptions: { project: path.resolve(__dirname, './tsconfig.json'), @@ -276,4 +276,7 @@ module.exports = { }, }, ], + rules: { + 'react-compiler/react-compiler': 'error', + } }; diff --git a/package-lock.json b/package-lock.json index eabb0e88e6a7..cbdaa9f8349b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -213,6 +213,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-jest": "^28.6.0", "eslint-plugin-jsdoc": "^46.2.6", + "eslint-plugin-react-compiler": "^0.0.0-experimental-53bb89e-20240515", "eslint-plugin-react-native-a11y": "^3.3.0", "eslint-plugin-storybook": "^0.8.0", "eslint-plugin-testing-library": "^6.2.2", @@ -402,20 +403,20 @@ } }, "node_modules/@babel/core": { - "version": "7.24.3", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.3.tgz", - "integrity": "sha512-5FcvN1JHw2sHJChotgx8Ek0lyuh4kCKelgMTTqhYJJtloNvUfpAFMeNQUtdlIaktwrSV9LtCdqwk48wL2wBacQ==", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.5.tgz", + "integrity": "sha512-tVQRucExLQ02Boi4vdPp49svNGcfL2GhdTCT9aldhXgCJVAI21EtRfBettiuLUwce/7r6bFdgs6JFkcdTiFttA==", "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.24.2", - "@babel/generator": "^7.24.1", + "@babel/generator": "^7.24.5", "@babel/helper-compilation-targets": "^7.23.6", - "@babel/helper-module-transforms": "^7.23.3", - "@babel/helpers": "^7.24.1", - "@babel/parser": "^7.24.1", + "@babel/helper-module-transforms": "^7.24.5", + "@babel/helpers": "^7.24.5", + "@babel/parser": "^7.24.5", "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.1", - "@babel/types": "^7.24.0", + "@babel/traverse": "^7.24.5", + "@babel/types": "^7.24.5", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -431,18 +432,18 @@ } }, "node_modules/@babel/core/node_modules/@babel/traverse": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.1.tgz", - "integrity": "sha512-xuU6o9m68KeqZbQuDt2TcKSxUw/mrsvavlEqQ1leZ/B+C9tk6E4sRWy97WaXgvq5E+nU3cXMxv3WKOCanVMCmQ==", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.5.tgz", + "integrity": "sha512-7aaBLeDQ4zYcUFDUD41lJc1fG8+5IU9DaNSJAgal866FGvmD5EbWQgnEC6kO1gGLsX0esNkfnJSndbTXA3r7UA==", "dependencies": { - "@babel/code-frame": "^7.24.1", - "@babel/generator": "^7.24.1", + "@babel/code-frame": "^7.24.2", + "@babel/generator": "^7.24.5", "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-function-name": "^7.23.0", "@babel/helper-hoist-variables": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/parser": "^7.24.1", - "@babel/types": "^7.24.0", + "@babel/helper-split-export-declaration": "^7.24.5", + "@babel/parser": "^7.24.5", + "@babel/types": "^7.24.5", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -489,11 +490,11 @@ } }, "node_modules/@babel/generator": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.1.tgz", - "integrity": "sha512-DfCRfZsBcrPEHUfuBMgbJ1Ut01Y/itOs+hY2nFLgqsqXd52/iSiVq5TITtUasIUgm+IIKdY2/1I7auiQOEeC9A==", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.5.tgz", + "integrity": "sha512-x32i4hEXvr+iI0NEoEfDKzlemF8AmtOP8CcrRaEcpzysWuoEb1KknpcvMsHKPONoKZiDuItklgWhB18xEhr9PA==", "dependencies": { - "@babel/types": "^7.24.0", + "@babel/types": "^7.24.5", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", "jsesc": "^2.5.1" @@ -693,15 +694,15 @@ } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.23.3", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.3.tgz", - "integrity": "sha512-7bBs4ED9OmswdfDzpz4MpWgSrV7FXlc3zIagvLFjS5H+Mk7Snr21vQ6QwrsoCGMfNC4e4LQPdoULEt4ykz0SRQ==", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.24.5.tgz", + "integrity": "sha512-9GxeY8c2d2mdQUP1Dye0ks3VDyIMS98kt/llQ2nUId8IsWqTF0l1LkSX0/uP7l7MCDrzXS009Hyhe2gzTiGW8A==", "dependencies": { "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-module-imports": "^7.22.15", - "@babel/helper-simple-access": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/helper-validator-identifier": "^7.22.20" + "@babel/helper-module-imports": "^7.24.3", + "@babel/helper-simple-access": "^7.24.5", + "@babel/helper-split-export-declaration": "^7.24.5", + "@babel/helper-validator-identifier": "^7.24.5" }, "engines": { "node": ">=6.9.0" @@ -761,10 +762,11 @@ } }, "node_modules/@babel/helper-simple-access": { - "version": "7.22.5", - "license": "MIT", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.5.tgz", + "integrity": "sha512-uH3Hmf5q5n7n8mz7arjUlDOCbttY/DW4DYhE6FUsjKJ/oYC1kQQUvwEQWxRwUpX9qQKRXeqLwWxrqilMrf32sQ==", "dependencies": { - "@babel/types": "^7.22.5" + "@babel/types": "^7.24.5" }, "engines": { "node": ">=6.9.0" @@ -781,25 +783,28 @@ } }, "node_modules/@babel/helper-split-export-declaration": { - "version": "7.22.6", - "license": "MIT", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.24.5.tgz", + "integrity": "sha512-5CHncttXohrHk8GWOFCcCl4oRD9fKosWlIRgWm4ql9VYioKm52Mk2xsmoohvm7f3JoiLSM5ZgJuRaf5QZZYd3Q==", "dependencies": { - "@babel/types": "^7.22.5" + "@babel/types": "^7.24.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.23.4", - "license": "MIT", + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.1.tgz", + "integrity": "sha512-2ofRCjnnA9y+wk8b9IAREroeUP02KHp431N2mhKniy2yKIDKpbrHv9eXwm8cBeWQYcJmzv5qKCu65P47eCF7CQ==", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.22.20", - "license": "MIT", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.5.tgz", + "integrity": "sha512-3q93SSKX2TWCG30M2G2kwaKeTYgEUp5Snjuj8qm729SObL6nbtUldAi37qbxkD5gg3xnBio+f9nqpSepGZMvxA==", "engines": { "node": ">=6.9.0" } @@ -825,31 +830,31 @@ } }, "node_modules/@babel/helpers": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.1.tgz", - "integrity": "sha512-BpU09QqEe6ZCHuIHFphEFgvNSrubve1FtyMton26ekZ85gRGi6LrTF7zArARp2YvyFxloeiRmtSCq5sjh1WqIg==", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.5.tgz", + "integrity": "sha512-CiQmBMMpMQHwM5m01YnrM6imUG1ebgYJ+fAIW4FZe6m4qHTPaRHti+R8cggAwkdz4oXhtO4/K9JWlh+8hIfR2Q==", "dependencies": { "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.1", - "@babel/types": "^7.24.0" + "@babel/traverse": "^7.24.5", + "@babel/types": "^7.24.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helpers/node_modules/@babel/traverse": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.1.tgz", - "integrity": "sha512-xuU6o9m68KeqZbQuDt2TcKSxUw/mrsvavlEqQ1leZ/B+C9tk6E4sRWy97WaXgvq5E+nU3cXMxv3WKOCanVMCmQ==", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.5.tgz", + "integrity": "sha512-7aaBLeDQ4zYcUFDUD41lJc1fG8+5IU9DaNSJAgal866FGvmD5EbWQgnEC6kO1gGLsX0esNkfnJSndbTXA3r7UA==", "dependencies": { - "@babel/code-frame": "^7.24.1", - "@babel/generator": "^7.24.1", + "@babel/code-frame": "^7.24.2", + "@babel/generator": "^7.24.5", "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-function-name": "^7.23.0", "@babel/helper-hoist-variables": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/parser": "^7.24.1", - "@babel/types": "^7.24.0", + "@babel/helper-split-export-declaration": "^7.24.5", + "@babel/parser": "^7.24.5", + "@babel/types": "^7.24.5", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -872,9 +877,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.1.tgz", - "integrity": "sha512-Zo9c7N3xdOIQrNip7Lc9wvRPzlRtovHVE4lkz8WEDr7uYh/GMQhSiIgFxGIArRHYdJE5kxtZjAf8rT0xhdLCzg==", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.5.tgz", + "integrity": "sha512-EOv5IK8arwh3LI47dz1b0tKUb/1uhHAnHJOrjgtQMIpu1uXd9mlFrJg9IUgGUgZ41Ch0K8REPTYpO7B76b4vJg==", "bin": { "parser": "bin/babel-parser.js" }, @@ -2563,12 +2568,12 @@ } }, "node_modules/@babel/types": { - "version": "7.24.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.0.tgz", - "integrity": "sha512-+j7a5c253RfKh8iABBhywc8NSfP5LURe7Uh4qpsh6jc+aLJguvmIUBdjSdEMQv2bENrCR5MfRdjGo7vzS/ob7w==", + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.5.tgz", + "integrity": "sha512-6mQNsaLeXTw0nxYUYu+NSa4Hx4BlF1x1x8/PMFbiR+GBSr+2DkECc69b8hgy2frEodNcvPffeH8YfWd3LI6jhQ==", "dependencies": { - "@babel/helper-string-parser": "^7.23.4", - "@babel/helper-validator-identifier": "^7.22.20", + "@babel/helper-string-parser": "^7.24.1", + "@babel/helper-validator-identifier": "^7.24.5", "to-fast-properties": "^2.0.0" }, "engines": { @@ -19788,6 +19793,41 @@ "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8" } }, + "node_modules/eslint-plugin-react-compiler": { + "version": "0.0.0-experimental-53bb89e-20240515", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-compiler/-/eslint-plugin-react-compiler-0.0.0-experimental-53bb89e-20240515.tgz", + "integrity": "sha512-L3HV9qja1dnClRlR9aaWEJeJoGPH9cgjKq0sYqIOOH9uyWdVMH9CudsFr6yLva7dj05FpLZkiIaRSZJ3P/v6yQ==", + "dev": true, + "dependencies": { + "@babel/core": "^7.24.4", + "@babel/parser": "^7.24.4", + "@babel/plugin-proposal-private-methods": "^7.18.6", + "hermes-parser": "^0.20.1", + "zod": "^3.22.4", + "zod-validation-error": "^3.0.3" + }, + "engines": { + "node": "^14.17.0 || ^16.0.0 || >= 18.0.0" + }, + "peerDependencies": { + "eslint": ">=7" + } + }, + "node_modules/eslint-plugin-react-compiler/node_modules/hermes-estree": { + "version": "0.20.1", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.20.1.tgz", + "integrity": "sha512-SQpZK4BzR48kuOg0v4pb3EAGNclzIlqMj3Opu/mu7bbAoFw6oig6cEt/RAi0zTFW/iW6Iz9X9ggGuZTAZ/yZHg==", + "dev": true + }, + "node_modules/eslint-plugin-react-compiler/node_modules/hermes-parser": { + "version": "0.20.1", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.20.1.tgz", + "integrity": "sha512-BL5P83cwCogI8D7rrDCgsFY0tdYUtmFP9XaXtl2IQjC+2Xo+4okjfXintlTxcIwl4qeGddEl28Z11kbVIw0aNA==", + "dev": true, + "dependencies": { + "hermes-estree": "0.20.1" + } + }, "node_modules/eslint-plugin-react-hooks": { "version": "4.6.0", "dev": true, @@ -38147,6 +38187,18 @@ "funding": { "url": "https://github.com/sponsors/colinhacks" } + }, + "node_modules/zod-validation-error": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/zod-validation-error/-/zod-validation-error-3.3.0.tgz", + "integrity": "sha512-Syib9oumw1NTqEv4LT0e6U83Td9aVRk9iTXPUQr1otyV1PuXQKOvOwhMNqZIq5hluzHP2pMgnOmHEo7kPdI2mw==", + "dev": true, + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "zod": "^3.18.0" + } } } } diff --git a/package.json b/package.json index 6228b5ec99ca..810a8263cafb 100644 --- a/package.json +++ b/package.json @@ -266,6 +266,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-jest": "^28.6.0", "eslint-plugin-jsdoc": "^46.2.6", + "eslint-plugin-react-compiler": "^0.0.0-experimental-53bb89e-20240515", "eslint-plugin-react-native-a11y": "^3.3.0", "eslint-plugin-storybook": "^0.8.0", "eslint-plugin-testing-library": "^6.2.2", diff --git a/patches/eslint-plugin-react-compiler+0.0.0-experimental-53bb89e-20240515.patch b/patches/eslint-plugin-react-compiler+0.0.0-experimental-53bb89e-20240515.patch new file mode 100644 index 000000000000..f81f70944dd2 --- /dev/null +++ b/patches/eslint-plugin-react-compiler+0.0.0-experimental-53bb89e-20240515.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/eslint-plugin-react-compiler/dist/index.js b/node_modules/eslint-plugin-react-compiler/dist/index.js +index a0f47a7..f649250 100644 +--- a/node_modules/eslint-plugin-react-compiler/dist/index.js ++++ b/node_modules/eslint-plugin-react-compiler/dist/index.js +@@ -69108,7 +69108,7 @@ const rule = { + return false; + } + let babelAST; +- if (context.filename.endsWith(".tsx") || context.filename.endsWith(".ts")) { ++ if (filename.endsWith(".tsx") || filename.endsWith(".ts")) { + try { + const { parse: babelParse } = require("@babel/parser"); + babelAST = babelParse(sourceCode, { From 84a1d3dc7ba45b615b330d5309e150f197448c0f Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Fri, 17 May 2024 11:10:20 +0200 Subject: [PATCH 02/11] feat: working react-compiler --- babel.config.js | 7 +- lib/react-compiler-runtime/index.js | 21 +++ lib/react-compiler-runtime/package.json | 10 ++ package-lock.json | 190 ++++++++++++++++++++++++ package.json | 2 + 5 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 lib/react-compiler-runtime/index.js create mode 100644 lib/react-compiler-runtime/package.json diff --git a/babel.config.js b/babel.config.js index e04e589166f4..110efa67c4ba 100644 --- a/babel.config.js +++ b/babel.config.js @@ -2,8 +2,12 @@ require('dotenv').config(); const IS_E2E_TESTING = process.env.E2E_TESTING === 'true'; +const ReactCompilerConfig = { + runtimeModule: "react-compiler-runtime", +}; const defaultPresets = ['@babel/preset-react', '@babel/preset-env', '@babel/preset-flow', '@babel/preset-typescript']; -let defaultPlugins = [ +const defaultPlugins = [ + ['babel-plugin-react-compiler', ReactCompilerConfig], // must run first! // Adding the commonjs: true option to react-native-web plugin can cause styling conflicts ['react-native-web'], @@ -39,6 +43,7 @@ const webpack = { const metro = { presets: [require('@react-native/babel-preset')], plugins: [ + ['babel-plugin-react-compiler', ReactCompilerConfig], // must run first! // This is needed due to a react-native bug: https://github.com/facebook/react-native/issues/29084#issuecomment-1030732709 // It is included in metro-react-native-babel-preset but needs to be before plugin-proposal-class-properties or FlatList will break '@babel/plugin-transform-flow-strip-types', diff --git a/lib/react-compiler-runtime/index.js b/lib/react-compiler-runtime/index.js new file mode 100644 index 000000000000..6ab16ce0b5b5 --- /dev/null +++ b/lib/react-compiler-runtime/index.js @@ -0,0 +1,21 @@ +// lib/react-compiler-runtime.js +const $empty = Symbol.for("react.memo_cache_sentinel"); +const React = require('react'); +/** + * DANGER: this hook is NEVER meant to be called directly! + * + * Note that this is a temporary userspace implementation of this function + * from React 19. It is not as efficient and may invalidate more frequently + * than the official API. Better to upgrade to React 19 as soon as we can. + **/ +export function c(size) { + return React.useState(() => { + const $ = new Array(size); + for (let ii = 0; ii < size; ii++) { + $[ii] = $empty; + } + // @ts-ignore + $[$empty] = true; + return $; + })[0]; +} \ No newline at end of file diff --git a/lib/react-compiler-runtime/package.json b/lib/react-compiler-runtime/package.json new file mode 100644 index 000000000000..1d114a658e36 --- /dev/null +++ b/lib/react-compiler-runtime/package.json @@ -0,0 +1,10 @@ +{ + "name": "react-forget-runtime", + "version": "0.0.1", + "description": "Runtime for React Forget", + "license": "MIT", + "main": "index.js", + "dependencies": { + "react": "^18.2.0" + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index cbdaa9f8349b..92e488709436 100644 --- a/package-lock.json +++ b/package-lock.json @@ -80,6 +80,7 @@ "react": "18.2.0", "react-beautiful-dnd": "^13.1.1", "react-collapse": "^5.1.0", + "react-compiler-runtime": "file:./lib/react-compiler-runtime", "react-content-loader": "^7.0.0", "react-dom": "18.1.0", "react-error-boundary": "^4.0.11", @@ -195,6 +196,7 @@ "babel-jest": "29.4.1", "babel-loader": "^9.1.3", "babel-plugin-module-resolver": "^5.0.0", + "babel-plugin-react-compiler": "^0.0.0-experimental-c23de8d-20240515", "babel-plugin-react-native-web": "^0.18.7", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-remove-console": "^6.9.4", @@ -256,6 +258,14 @@ "npm": "10.7.0" } }, + "lib/react-compiler-runtime": { + "name": "react-forget-runtime", + "version": "0.0.1", + "license": "MIT", + "dependencies": { + "react": "^18.2.0" + } + }, "node_modules/@actions/core": { "version": "1.10.0", "dev": true, @@ -15034,6 +15044,173 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/babel-plugin-react-compiler": { + "version": "0.0.0-experimental-c23de8d-20240515", + "resolved": "https://registry.npmjs.org/babel-plugin-react-compiler/-/babel-plugin-react-compiler-0.0.0-experimental-c23de8d-20240515.tgz", + "integrity": "sha512-0XN2gmpT55QtAz5n7d5g91y1AuO9tRhWBaLgCRyc4ExHrlr7+LfxW+YTb3mOwxngkkiggwM8HyYsaEK9MqhnlQ==", + "dev": true, + "dependencies": { + "@babel/generator": "7.2.0", + "@babel/types": "^7.19.0", + "chalk": "4", + "invariant": "^2.2.4", + "pretty-format": "^24", + "zod": "^3.22.4", + "zod-validation-error": "^2.1.0" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/@babel/generator": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.2.0.tgz", + "integrity": "sha512-BA75MVfRlFQG2EZgFYIwyT1r6xSkwfP2bdkY/kLZusEYWiJs4xCowab/alaEaT0wSvmVuXGqiefeBlP+7V1yKg==", + "dev": true, + "dependencies": { + "@babel/types": "^7.2.0", + "jsesc": "^2.5.1", + "lodash": "^4.17.10", + "source-map": "^0.5.0", + "trim-right": "^1.0.1" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/@jest/types": { + "version": "24.9.0", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-24.9.0.tgz", + "integrity": "sha512-XKK7ze1apu5JWQ5eZjHITP66AX+QsLlbaJRBGYr8pNzwcAE2JVkwnf0yqjHTsDRcjR0mujy/NmZMXw5kl+kGBw==", + "dev": true, + "dependencies": { + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^1.1.1", + "@types/yargs": "^13.0.0" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/@types/istanbul-reports": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-1.1.2.tgz", + "integrity": "sha512-P/W9yOX/3oPZSpaYOCQzGqgCQRXn0FFO/V8bWrCQs+wLmvVVxk6CRBXALEvNs9OHIatlnlFokfhuDo2ug01ciw==", + "dev": true, + "dependencies": { + "@types/istanbul-lib-coverage": "*", + "@types/istanbul-lib-report": "*" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/@types/yargs": { + "version": "13.0.12", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.12.tgz", + "integrity": "sha512-qCxJE1qgz2y0hA4pIxjBR+PelCH0U5CK1XJXFwCNqfmliatKp47UCXXE9Dyk1OXBDLvsCF57TqQEJaeLfDYEOQ==", + "dev": true, + "dependencies": { + "@types/yargs-parser": "*" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/chalk/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/babel-plugin-react-compiler/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/pretty-format": { + "version": "24.9.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-24.9.0.tgz", + "integrity": "sha512-00ZMZUiHaJrNfk33guavqgvfJS30sLYf0f8+Srklv0AMPodGGHcoHgksZ3OThYnIvOd+8yMCn0YiEOogjlgsnA==", + "dev": true, + "dependencies": { + "@jest/types": "^24.9.0", + "ansi-regex": "^4.0.0", + "ansi-styles": "^3.2.0", + "react-is": "^16.8.4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/babel-plugin-react-compiler/node_modules/zod-validation-error": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/zod-validation-error/-/zod-validation-error-2.1.0.tgz", + "integrity": "sha512-VJh93e2wb4c3tWtGgTa0OF/dTt/zoPCPzXq4V11ZjxmEAFaPi/Zss1xIZdEB5RD8GD00U0/iVXgqkF77RV7pdQ==", + "dev": true, + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "zod": "^3.18.0" + } + }, "node_modules/babel-plugin-react-native-web": { "version": "0.18.12", "license": "MIT" @@ -31135,6 +31312,10 @@ "react-dom": ">=16.8.0" } }, + "node_modules/react-compiler-runtime": { + "resolved": "lib/react-compiler-runtime", + "link": true + }, "node_modules/react-content-loader": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/react-content-loader/-/react-content-loader-7.0.0.tgz", @@ -35873,6 +36054,15 @@ "tree-kill": "cli.js" } }, + "node_modules/trim-right": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", + "integrity": "sha512-WZGXGstmCWgeevgTL54hrCuw1dyMQIzWy7ZfqRJfSmJZBwklI15egmQytFP6bPidmw3M8d5yEowl1niq4vmqZw==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/truncate-utf8-bytes": { "version": "1.0.2", "dev": true, diff --git a/package.json b/package.json index 810a8263cafb..0c5b7f28259f 100644 --- a/package.json +++ b/package.json @@ -133,6 +133,7 @@ "react": "18.2.0", "react-beautiful-dnd": "^13.1.1", "react-collapse": "^5.1.0", + "react-compiler-runtime": "file:./lib/react-compiler-runtime", "react-content-loader": "^7.0.0", "react-dom": "18.1.0", "react-error-boundary": "^4.0.11", @@ -248,6 +249,7 @@ "babel-jest": "29.4.1", "babel-loader": "^9.1.3", "babel-plugin-module-resolver": "^5.0.0", + "babel-plugin-react-compiler": "^0.0.0-experimental-c23de8d-20240515", "babel-plugin-react-native-web": "^0.18.7", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-remove-console": "^6.9.4", From c94795c54e66c252dd309feb9e28f7e704c1a085 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Fri, 17 May 2024 11:51:13 +0200 Subject: [PATCH 03/11] fix: eslint --- .eslintrc.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 569cf6b6ee04..b20591b22bfa 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -187,6 +187,7 @@ module.exports = { touchables: ['PressableWithoutFeedback', 'PressableWithFeedback'], }, ], + 'react-compiler/react-compiler': 'error', // Disallow usage of certain functions and imports 'no-restricted-syntax': [ @@ -276,7 +277,4 @@ module.exports = { }, }, ], - rules: { - 'react-compiler/react-compiler': 'error', - } }; From 1d860e7d6b0f29c7a65435f992152ef76eb11ac8 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Fri, 17 May 2024 12:16:45 +0200 Subject: [PATCH 04/11] fix: lint again --- .eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.js b/.eslintrc.js index b20591b22bfa..e5a1f4534f20 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -96,6 +96,7 @@ module.exports = { 'prettier', ], plugins: ['@typescript-eslint', 'jsdoc', 'you-dont-need-lodash-underscore', 'react-native-a11y', 'react', 'testing-library', 'eslint-plugin-react-compiler'], + ignorePatterns: ["lib/**"], parser: '@typescript-eslint/parser', parserOptions: { project: path.resolve(__dirname, './tsconfig.json'), From 9d40f6599e465d156571049b328271ec4a9a4d23 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Fri, 17 May 2024 16:45:58 +0200 Subject: [PATCH 05/11] fix: definetely fixed eslint --- .eslintrc.js | 2 +- .prettierignore | 2 ++ babel.config.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index e5a1f4534f20..22bb0158bc8e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -96,7 +96,7 @@ module.exports = { 'prettier', ], plugins: ['@typescript-eslint', 'jsdoc', 'you-dont-need-lodash-underscore', 'react-native-a11y', 'react', 'testing-library', 'eslint-plugin-react-compiler'], - ignorePatterns: ["lib/**"], + ignorePatterns: ['lib/**'], parser: '@typescript-eslint/parser', parserOptions: { project: path.resolve(__dirname, './tsconfig.json'), diff --git a/.prettierignore b/.prettierignore index 2df776736b69..d6ccc4321280 100644 --- a/.prettierignore +++ b/.prettierignore @@ -17,3 +17,5 @@ package-lock.json *.md # We need to modify the import here specifically, hence we disable prettier to get rid of the sorted imports src/libs/E2E/reactNativeLaunchingTest.ts +# Temporary while we keep react-compiler in our repo +lib/** \ No newline at end of file diff --git a/babel.config.js b/babel.config.js index 110efa67c4ba..91f6be6cdddc 100644 --- a/babel.config.js +++ b/babel.config.js @@ -3,7 +3,7 @@ require('dotenv').config(); const IS_E2E_TESTING = process.env.E2E_TESTING === 'true'; const ReactCompilerConfig = { - runtimeModule: "react-compiler-runtime", + runtimeModule: 'react-compiler-runtime', }; const defaultPresets = ['@babel/preset-react', '@babel/preset-env', '@babel/preset-flow', '@babel/preset-typescript']; const defaultPlugins = [ From 22663947d44e37a62efd76a63102e6a6874fc510 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Fri, 17 May 2024 16:51:19 +0200 Subject: [PATCH 06/11] fix: consistent eol --- .prettierignore | 2 +- lib/react-compiler-runtime/index.js | 2 +- lib/react-compiler-runtime/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.prettierignore b/.prettierignore index d6ccc4321280..09de20ba30b0 100644 --- a/.prettierignore +++ b/.prettierignore @@ -18,4 +18,4 @@ package-lock.json # We need to modify the import here specifically, hence we disable prettier to get rid of the sorted imports src/libs/E2E/reactNativeLaunchingTest.ts # Temporary while we keep react-compiler in our repo -lib/** \ No newline at end of file +lib/** diff --git a/lib/react-compiler-runtime/index.js b/lib/react-compiler-runtime/index.js index 6ab16ce0b5b5..54e88d2b703a 100644 --- a/lib/react-compiler-runtime/index.js +++ b/lib/react-compiler-runtime/index.js @@ -18,4 +18,4 @@ export function c(size) { $[$empty] = true; return $; })[0]; -} \ No newline at end of file +} diff --git a/lib/react-compiler-runtime/package.json b/lib/react-compiler-runtime/package.json index 1d114a658e36..df5e86b68326 100644 --- a/lib/react-compiler-runtime/package.json +++ b/lib/react-compiler-runtime/package.json @@ -7,4 +7,4 @@ "dependencies": { "react": "^18.2.0" } -} \ No newline at end of file +} From 667cfbe6d6ab95ed1768649d51c68116c85e1e8e Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Fri, 17 May 2024 16:52:22 +0200 Subject: [PATCH 07/11] fix: forget -> compiler --- lib/react-compiler-runtime/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/react-compiler-runtime/package.json b/lib/react-compiler-runtime/package.json index df5e86b68326..86de67e130ce 100644 --- a/lib/react-compiler-runtime/package.json +++ b/lib/react-compiler-runtime/package.json @@ -1,7 +1,7 @@ { - "name": "react-forget-runtime", + "name": "react-compiler-runtime", "version": "0.0.1", - "description": "Runtime for React Forget", + "description": "Runtime for React Compiler", "license": "MIT", "main": "index.js", "dependencies": { From fdb58040bd8eb9b79d825d16c3db058f8f1ccad0 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Tue, 28 May 2024 14:08:07 +0200 Subject: [PATCH 08/11] fix: CI --- babel.config.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/babel.config.js b/babel.config.js index 91f6be6cdddc..9b4b83408093 100644 --- a/babel.config.js +++ b/babel.config.js @@ -43,7 +43,6 @@ const webpack = { const metro = { presets: [require('@react-native/babel-preset')], plugins: [ - ['babel-plugin-react-compiler', ReactCompilerConfig], // must run first! // This is needed due to a react-native bug: https://github.com/facebook/react-native/issues/29084#issuecomment-1030732709 // It is included in metro-react-native-babel-preset but needs to be before plugin-proposal-class-properties or FlatList will break '@babel/plugin-transform-flow-strip-types', @@ -146,5 +145,13 @@ module.exports = (api) => { const runningIn = api.caller((args = {}) => args.name); console.debug(' - running in: ', runningIn); + // don't include react-compiler in jest, because otherwise tests will fail + if (runningIn !== 'babel-jest') { + // must run first! + metro.plugins.unshift(['babel-plugin-react-compiler', ReactCompilerConfig]); + } + + console.log(metro); + return ['metro', 'babel-jest'].includes(runningIn) ? metro : webpack; }; From 92d49ff3967cb2604dba07768c380fc9e6b469d7 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Tue, 28 May 2024 14:42:52 +0200 Subject: [PATCH 09/11] chore: changes after self review --- babel.config.js | 2 -- package-lock.json | 1 - 2 files changed, 3 deletions(-) diff --git a/babel.config.js b/babel.config.js index 9b4b83408093..7010404f2a31 100644 --- a/babel.config.js +++ b/babel.config.js @@ -151,7 +151,5 @@ module.exports = (api) => { metro.plugins.unshift(['babel-plugin-react-compiler', ReactCompilerConfig]); } - console.log(metro); - return ['metro', 'babel-jest'].includes(runningIn) ? metro : webpack; }; diff --git a/package-lock.json b/package-lock.json index 92e488709436..6c6dd6aa48ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -259,7 +259,6 @@ } }, "lib/react-compiler-runtime": { - "name": "react-forget-runtime", "version": "0.0.1", "license": "MIT", "dependencies": { From 1c91f6a8a551fe9fd7d48e66b1bfa8096c622775 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Wed, 5 Jun 2024 10:54:12 +0200 Subject: [PATCH 10/11] fix: update authorChecklist --- .../javascript/authorChecklist/index.js | 285 ++++++++++-------- 1 file changed, 162 insertions(+), 123 deletions(-) diff --git a/.github/actions/javascript/authorChecklist/index.js b/.github/actions/javascript/authorChecklist/index.js index 73180a458dc9..d82a71bbab73 100644 --- a/.github/actions/javascript/authorChecklist/index.js +++ b/.github/actions/javascript/authorChecklist/index.js @@ -21146,7 +21146,8 @@ function TSMappedType(node) { nameType, optional, readonly, - typeParameter + typeParameter, + typeAnnotation } = node; this.tokenChar(123); this.space(); @@ -21172,9 +21173,11 @@ function TSMappedType(node) { tokenIfPlusMinus(this, optional); this.tokenChar(63); } - this.tokenChar(58); - this.space(); - this.print(node.typeAnnotation, node); + if (typeAnnotation) { + this.tokenChar(58); + this.space(); + this.print(typeAnnotation, node); + } this.space(); this.tokenChar(125); } @@ -22335,7 +22338,7 @@ class Printer { } this._printStack.push(node); const oldInAux = this._insideAux; - this._insideAux = node.loc == undefined; + this._insideAux = node.loc == null; this._maybeAddAuxComment(this._insideAux && !oldInAux); const parenthesized = (_node$extra = node.extra) == null ? void 0 : _node$extra.parenthesized; let shouldPrintParens = forceParens || parenthesized && format.retainFunctionParens && nodeType === "FunctionExpression" || needsParens(node, parent, this._printStack); @@ -22628,7 +22631,7 @@ class Printer { if (type === 0) { let offset = 0; if (i === 0) { - if (this._buf.hasContent() && (comment.type === "CommentLine" || commentStartLine != commentEndLine)) { + if (this._buf.hasContent() && (comment.type === "CommentLine" || commentStartLine !== commentEndLine)) { offset = leadingCommentNewline = 1; } } else { @@ -23857,10 +23860,7 @@ const NodeDescriptions = { VariableDeclarator: "variable declaration", YieldExpression: "yield expression" }; -const toNodeDescription = ({ - type, - prefix -}) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type]; +const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type]; var StandardErrors = { AccessorIsGenerator: ({ kind @@ -24071,6 +24071,7 @@ var StandardErrors = { UnterminatedRegExp: "Unterminated regular expression.", UnterminatedString: "Unterminated string constant.", UnterminatedTemplate: "Unterminated template.", + UsingDeclarationExport: "Using declaration cannot be exported.", UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.", VarRedeclaration: ({ identifierName @@ -24360,6 +24361,10 @@ var estree = superClass => class ESTreeParserMixin extends superClass { } return this.finishNode(node, "MethodDefinition"); } + nameIsConstructor(key) { + if (key.type === "Literal") return key.value === "constructor"; + return super.nameIsConstructor(key); + } parseClassProperty(...args) { const propertyNode = super.parseClassProperty(...args); { @@ -24424,9 +24429,9 @@ var estree = superClass => class ESTreeParserMixin extends superClass { } } toAssignableObjectExpressionProp(prop, isLast, isLHS) { - if (prop.kind === "get" || prop.kind === "set") { + if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) { this.raise(Errors.PatternHasAccessor, prop.key); - } else if (prop.method) { + } else if (prop.type === "Property" && prop.method) { this.raise(Errors.PatternHasMethod, prop.key); } else { super.toAssignableObjectExpressionProp(prop, isLast, isLHS); @@ -24438,9 +24443,9 @@ var estree = superClass => class ESTreeParserMixin extends superClass { node.type = "ImportExpression"; node.source = node.arguments[0]; if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) { - var _node$arguments$, _node$arguments$2; - node.options = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null; - node.attributes = (_node$arguments$2 = node.arguments[1]) != null ? _node$arguments$2 : null; + var _ref, _ref2; + node.options = (_ref = node.arguments[1]) != null ? _ref : null; + node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null; } delete node.arguments; delete node.callee; @@ -24512,7 +24517,7 @@ var estree = superClass => class ESTreeParserMixin extends superClass { return node.type === "Property" && node.kind === "init" && !node.method; } isObjectMethod(node) { - return node.method || node.kind === "get" || node.kind === "set"; + return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set"); } finishNodeAt(node, type, endLoc) { return toESTreeLocation(super.finishNodeAt(node, type, endLoc)); @@ -25415,7 +25420,9 @@ class CommentsParser extends BaseParser { const { commentsLen } = this.state; - if (this.comments.length != commentsLen) this.comments.length = commentsLen; + if (this.comments.length !== commentsLen) { + this.comments.length = commentsLen; + } this.comments.push(comment); this.state.commentsLen++; } @@ -28589,50 +28596,56 @@ var flow = superClass => class FlowParserMixin extends superClass { this.state.noAnonFunctionType = oldNoAnonFunctionType; return type; case 47: - node.typeParameters = this.flowParseTypeParameterDeclaration(); - this.expect(10); - tmp = this.flowParseFunctionTypeParams(); - node.params = tmp.params; - node.rest = tmp.rest; - node.this = tmp._this; - this.expect(11); - this.expect(19); - node.returnType = this.flowParseType(); - return this.finishNode(node, "FunctionTypeAnnotation"); + { + const node = this.startNode(); + node.typeParameters = this.flowParseTypeParameterDeclaration(); + this.expect(10); + tmp = this.flowParseFunctionTypeParams(); + node.params = tmp.params; + node.rest = tmp.rest; + node.this = tmp._this; + this.expect(11); + this.expect(19); + node.returnType = this.flowParseType(); + return this.finishNode(node, "FunctionTypeAnnotation"); + } case 10: - this.next(); - if (!this.match(11) && !this.match(21)) { - if (tokenIsIdentifier(this.state.type) || this.match(78)) { - const token = this.lookahead().type; - isGroupedType = token !== 17 && token !== 14; - } else { - isGroupedType = true; + { + const node = this.startNode(); + this.next(); + if (!this.match(11) && !this.match(21)) { + if (tokenIsIdentifier(this.state.type) || this.match(78)) { + const token = this.lookahead().type; + isGroupedType = token !== 17 && token !== 14; + } else { + isGroupedType = true; + } } - } - if (isGroupedType) { - this.state.noAnonFunctionType = false; - type = this.flowParseType(); - this.state.noAnonFunctionType = oldNoAnonFunctionType; - if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) { - this.expect(11); - return type; + if (isGroupedType) { + this.state.noAnonFunctionType = false; + type = this.flowParseType(); + this.state.noAnonFunctionType = oldNoAnonFunctionType; + if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) { + this.expect(11); + return type; + } else { + this.eat(12); + } + } + if (type) { + tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]); } else { - this.eat(12); + tmp = this.flowParseFunctionTypeParams(); } + node.params = tmp.params; + node.rest = tmp.rest; + node.this = tmp._this; + this.expect(11); + this.expect(19); + node.returnType = this.flowParseType(); + node.typeParameters = null; + return this.finishNode(node, "FunctionTypeAnnotation"); } - if (type) { - tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]); - } else { - tmp = this.flowParseFunctionTypeParams(); - } - node.params = tmp.params; - node.rest = tmp.rest; - node.this = tmp._this; - this.expect(11); - this.expect(19); - node.returnType = this.flowParseType(); - node.typeParameters = null; - return this.finishNode(node, "FunctionTypeAnnotation"); case 133: return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation"); case 85: @@ -28948,7 +28961,7 @@ var flow = superClass => class FlowParserMixin extends superClass { const arrows = []; while (stack.length !== 0) { const node = stack.pop(); - if (node.type === "ArrowFunctionExpression") { + if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") { if (node.typeParameters || !node.returnType) { this.finishArrowValidation(node); } else { @@ -28985,18 +28998,18 @@ var flow = superClass => class FlowParserMixin extends superClass { return result; } parseParenItem(node, startLoc) { - node = super.parseParenItem(node, startLoc); + const newNode = super.parseParenItem(node, startLoc); if (this.eat(17)) { - node.optional = true; + newNode.optional = true; this.resetEndLocation(node); } if (this.match(14)) { const typeCastNode = this.startNodeAt(startLoc); - typeCastNode.expression = node; + typeCastNode.expression = newNode; typeCastNode.typeAnnotation = this.flowParseTypeAnnotation(); return this.finishNode(typeCastNode, "TypeCastExpression"); } - return node; + return newNode; } assertModuleNodeAllowed(node) { if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") { @@ -30369,7 +30382,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { } else { let count = 0; let semi = false; - while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) { + while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) { ++this.state.pos; } if (semi) { @@ -30531,7 +30544,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { children.push(this.jsxParseElementAt(startLoc)); break; case 141: - children.push(this.parseExprAtom()); + children.push(this.parseLiteral(this.state.value, "JSXText")); break; case 5: { @@ -30588,9 +30601,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { context[context.length - 1] = newContext; } parseExprAtom(refExpressionErrors) { - if (this.match(141)) { - return this.parseLiteral(this.state.value, "JSXText"); - } else if (this.match(142)) { + if (this.match(142)) { return this.jsxParseElement(); } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) { this.replaceToken(142); @@ -30671,14 +30682,14 @@ class TypeScriptScopeHandler extends ScopeHandler { return new TypeScriptScope(flags); } enter(flags) { - if (flags == 256) { + if (flags === 256) { this.importsStack.push(new Set()); } super.enter(flags); } exit() { const flags = super.exit(); - if (flags == 256) { + if (flags === 256) { this.importsStack.pop(); } return flags; @@ -30987,14 +30998,15 @@ class LValParser extends NodeUtils { return this.finishNode(prop, "RestElement"); } parseBindingProperty() { - const prop = this.startNode(); const { type, startLoc } = this.state; if (type === 21) { - return this.parseBindingRestProperty(prop); - } else if (type === 138) { + return this.parseBindingRestProperty(this.startNode()); + } + const prop = this.startNode(); + if (type === 138) { this.expectPlugin("destructuringPrivate", startLoc); this.classScope.usePrivateName(this.state.value, startLoc); prop.key = this.parsePrivateName(); @@ -32844,13 +32856,14 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { parseExport(node, decorators) { if (this.match(83)) { this.next(); + const nodeImportEquals = node; let maybeDefaultIdentifier = null; if (this.isContextual(130) && this.isPotentialImportPhase(false)) { - maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false); + maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false); } else { - node.importKind = "value"; + nodeImportEquals.importKind = "value"; } - return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, true); + return this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true); } else if (this.eat(29)) { const assign = node; assign.expression = super.parseExpression(); @@ -33022,9 +33035,9 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { return result.node; } parseParenItem(node, startLoc) { - node = super.parseParenItem(node, startLoc); + const newNode = super.parseParenItem(node, startLoc); if (this.eat(17)) { - node.optional = true; + newNode.optional = true; this.resetEndLocation(node); } if (this.match(14)) { @@ -33133,7 +33146,9 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } declareClassPrivateMethodInScope(node, kind) { if (node.type === "TSDeclareMethod") return; - if (node.type === "MethodDefinition" && !node.value.body) return; + if (node.type === "MethodDefinition" && !hasOwnProperty.call(node.value, "body")) { + return; + } super.declareClassPrivateMethodInScope(node, kind); } parseClassSuper(node) { @@ -33685,9 +33700,12 @@ var placeholders = superClass => class PlaceholdersParserMixin extends superClas } } finishPlaceholder(node, expectedNode) { - const isFinished = !!(node.expectedNode && node.type === "Placeholder"); - node.expectedNode = expectedNode; - return isFinished ? node : this.finishNode(node, "Placeholder"); + let placeholder = node; + if (!placeholder.expectedNode || !placeholder.type) { + placeholder = this.finishNode(placeholder, "Placeholder"); + } + placeholder.expectedNode = expectedNode; + return placeholder; } getTokenFromCode(code) { if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) { @@ -33747,8 +33765,9 @@ var placeholders = superClass => class PlaceholdersParserMixin extends superClas return this.finishNode(stmt, "LabeledStatement"); } this.semicolon(); - node.name = expr.name; - return this.finishPlaceholder(node, "Statement"); + const stmtPlaceholder = node; + stmtPlaceholder.name = expr.name; + return this.finishPlaceholder(stmtPlaceholder, "Statement"); } parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) { return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse); @@ -33781,17 +33800,18 @@ var placeholders = superClass => class PlaceholdersParserMixin extends superClas parseExport(node, decorators) { const placeholder = this.parsePlaceholder("Identifier"); if (!placeholder) return super.parseExport(node, decorators); + const node2 = node; if (!this.isContextual(98) && !this.match(12)) { - node.specifiers = []; - node.source = null; - node.declaration = this.finishPlaceholder(placeholder, "Declaration"); - return this.finishNode(node, "ExportNamedDeclaration"); + node2.specifiers = []; + node2.source = null; + node2.declaration = this.finishPlaceholder(placeholder, "Declaration"); + return this.finishNode(node2, "ExportNamedDeclaration"); } this.expectPlugin("exportDefaultFrom"); const specifier = this.startNode(); specifier.exported = placeholder; - node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; - return super.parseExport(node, decorators); + node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; + return super.parseExport(node2, decorators); } isExportDefaultSpecifier() { if (this.match(65)) { @@ -35091,14 +35111,16 @@ class ExpressionParser extends LValParser { } parseTemplate(isTagged) { const node = this.startNode(); - node.expressions = []; let curElt = this.parseTemplateElement(isTagged); - node.quasis = [curElt]; + const quasis = [curElt]; + const substitutions = []; while (!curElt.tail) { - node.expressions.push(this.parseTemplateSubstitution()); + substitutions.push(this.parseTemplateSubstitution()); this.readTemplateContinuation(); - node.quasis.push(curElt = this.parseTemplateElement(isTagged)); + quasis.push(curElt = this.parseTemplateElement(isTagged)); } + node.expressions = substitutions; + node.quasis = quasis; return this.finishNode(node, "TemplateLiteral"); } parseTemplateSubstitution() { @@ -35186,8 +35208,11 @@ class ExpressionParser extends LValParser { let isGenerator = this.eat(55); this.parsePropertyNamePrefixOperator(prop); const containsEsc = this.state.containsEsc; - const key = this.parsePropertyName(prop, refExpressionErrors); + this.parsePropertyName(prop, refExpressionErrors); if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) { + const { + key + } = prop; const keyName = key.name; if (keyName === "async" && !this.hasPrecedingLineBreak()) { isAsync = true; @@ -35322,7 +35347,6 @@ class ExpressionParser extends LValParser { prop.computed = false; } } - return prop.key; } initFunction(node, isAsync) { node.id = null; @@ -36645,9 +36669,9 @@ class StatementParser extends ExpressionParser { this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, { kind: "destructuring" }); - } else if (kind === "const" && !(this.match(58) || this.isContextual(102))) { + } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) { this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, { - kind: "const" + kind }); } } @@ -36732,8 +36756,11 @@ class StatementParser extends ExpressionParser { isClassMethod() { return this.match(10); } + nameIsConstructor(key) { + return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor"; + } isNonstaticConstructor(method) { - return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor"); + return !method.computed && !method.static && this.nameIsConstructor(method.key); } parseClassBody(hadSuperClass, oldStrict) { this.classScope.enter(); @@ -36835,9 +36862,10 @@ class StatementParser extends ExpressionParser { this.pushClassMethod(classBody, publicMethod, true, false, false, false); return; } - const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc; - const isPrivate = this.match(138); + const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type); const key = this.parseClassElementName(member); + const maybeContextualKw = isContextual ? key.name : null; + const isPrivate = this.isPrivateName(key); const maybeQuestionTokenStartLoc = this.state.startLoc; this.parsePostMemberNameModifiers(publicMember); if (this.isClassMethod()) { @@ -36866,7 +36894,7 @@ class StatementParser extends ExpressionParser { } else { this.pushClassProperty(classBody, publicProp); } - } else if (isContextual && key.name === "async" && !this.isLineTerminator()) { + } else if (maybeContextualKw === "async" && !this.isLineTerminator()) { this.resetPreviousNodeTrailingComments(key); const isGenerator = this.eat(55); if (publicMember.optional) { @@ -36884,9 +36912,9 @@ class StatementParser extends ExpressionParser { } this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false); } - } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) { + } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) { this.resetPreviousNodeTrailingComments(key); - method.kind = key.name; + method.kind = maybeContextualKw; const isPrivate = this.match(138); this.parseClassElementName(publicMethod); if (isPrivate) { @@ -36898,7 +36926,7 @@ class StatementParser extends ExpressionParser { this.pushClassMethod(classBody, publicMethod, false, false, false, false); } this.checkGetterSetterParams(publicMethod); - } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) { + } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) { this.expectPlugin("decoratorAutoAccessors"); this.resetPreviousNodeTrailingComments(key); const isPrivate = this.match(138); @@ -36930,7 +36958,8 @@ class StatementParser extends ExpressionParser { member.key = key; return key; } - return this.parsePropertyName(member); + this.parsePropertyName(member); + return member.key; } parseClassStaticBlock(classBody, member) { var _member$decorators; @@ -36949,7 +36978,7 @@ class StatementParser extends ExpressionParser { } } pushClassProperty(classBody, prop) { - if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) { + if (!prop.computed && this.nameIsConstructor(prop.key)) { this.raise(Errors.ConstructorClassField, prop.key); } classBody.body.push(this.parseClassProperty(prop)); @@ -36960,11 +36989,8 @@ class StatementParser extends ExpressionParser { this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start); } pushClassAccessorProperty(classBody, prop, isPrivate) { - if (!isPrivate && !prop.computed) { - const key = prop.key; - if (key.name === "constructor" || key.value === "constructor") { - this.raise(Errors.ConstructorClassField, key); - } + if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) { + this.raise(Errors.ConstructorClassField, prop.key); } const node = this.parseClassAccessorProperty(prop); classBody.body.push(node); @@ -37100,7 +37126,8 @@ class StatementParser extends ExpressionParser { } maybeParseExportNamespaceSpecifier(node) { if (this.isContextual(93)) { - if (!node.specifiers) node.specifiers = []; + var _ref, _ref$specifiers; + (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = []; const specifier = this.startNodeAt(this.state.lastTokStartLoc); this.next(); specifier.exported = this.parseModuleExportName(); @@ -37111,13 +37138,14 @@ class StatementParser extends ExpressionParser { } maybeParseExportNamedSpecifiers(node) { if (this.match(5)) { - if (!node.specifiers) node.specifiers = []; - const isTypeExport = node.exportKind === "type"; - node.specifiers.push(...this.parseExportSpecifiers(isTypeExport)); - node.source = null; - node.declaration = null; + const node2 = node; + if (!node2.specifiers) node2.specifiers = []; + const isTypeExport = node2.exportKind === "type"; + node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport)); + node2.source = null; + node2.declaration = null; if (this.hasPlugin("importAssertions")) { - node.assertions = []; + node2.assertions = []; } return true; } @@ -37228,6 +37256,14 @@ class StatementParser extends ExpressionParser { return true; } } + if (this.isContextual(107)) { + this.raise(Errors.UsingDeclarationExport, this.state.startLoc); + return true; + } + if (this.isContextual(96) && this.startsAwaitUsing()) { + this.raise(Errors.UsingDeclarationExport, this.state.startLoc); + return true; + } return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction(); } checkExport(node, checkNames, isDefault, isFrom) { @@ -37265,12 +37301,15 @@ class StatementParser extends ExpressionParser { } } } else if (node.declaration) { - if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") { - const id = node.declaration.id; + const decl = node.declaration; + if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") { + const { + id + } = decl; if (!id) throw new Error("Assertion failure"); this.checkDuplicateExports(node, id.name); - } else if (node.declaration.type === "VariableDeclaration") { - for (const declaration of node.declaration.declarations) { + } else if (decl.type === "VariableDeclaration") { + for (const declaration of decl.declarations) { this.checkDeclaration(declaration.id); } } @@ -49871,7 +49910,7 @@ defineType("CallExpression", { validate: (0, _utils.assertNodeType)("Expression", "Super", "V8IntrinsicIdentifier") }, arguments: { - validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "JSXNamespacedName", "ArgumentPlaceholder"))) + validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "ArgumentPlaceholder"))) } }, !process.env.BABEL_TYPES_8_BREAKING ? { optional: { @@ -51258,7 +51297,7 @@ defineType("OptionalCallExpression", { validate: (0, _utils.assertNodeType)("Expression") }, arguments: { - validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "JSXNamespacedName", "ArgumentPlaceholder"))) + validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "ArgumentPlaceholder"))) }, optional: { validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("boolean") : (0, _utils.chain)((0, _utils.assertValueType)("boolean"), (0, _utils.assertOptionalChainStart)()) From bfaddadbfb5fa1a8e2ebe616913f3dc6ca3fea21 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Sun, 16 Jun 2024 14:52:33 +0300 Subject: [PATCH 11/11] fix: QRCode page crash --- src/pages/ShareCodePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ShareCodePage.tsx b/src/pages/ShareCodePage.tsx index 347dc9694f31..9dfb5ae07a47 100644 --- a/src/pages/ShareCodePage.tsx +++ b/src/pages/ShareCodePage.tsx @@ -68,7 +68,7 @@ function ShareCodePage({report}: ShareCodePageProps) { Navigation.goBack(isReport ? ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report.reportID) : undefined)} + onBackButtonPress={() => Navigation.goBack(isReport ? ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID) : undefined)} shouldShowBackButton />