[eslint-plugin] Try using HermesParser

This commit is contained in:
Lauren Tan
2023-06-20 12:30:05 -04:00
parent 059365d726
commit 79dbf6fc19
4 changed files with 29 additions and 4 deletions
@@ -23,7 +23,8 @@
"@babel/traverse": "^7.19.1",
"babel-plugin-fbt": "^1.0.0",
"babel-plugin-fbt-runtime": "^1.0.0",
"babel-plugin-react-forget": "*"
"babel-plugin-react-forget": "*",
"hermes-parser": "^0.12.1"
},
"devDependencies": {
"@babel/eslint-parser": "^7.19.1",
@@ -6,12 +6,12 @@
*/
import { transformFromAstSync } from "@babel/core";
import * as parser from "@babel/parser";
import ReactForgetBabelPlugin, {
CompilerError,
type PluginOptions,
} from "babel-plugin-react-forget";
import type { Rule } from "eslint";
import * as HermesParser from "hermes-parser";
const rule: Rule.RuleModule = {
meta: {
@@ -35,9 +35,9 @@ const rule: Rule.RuleModule = {
validateRefAccessDuringRender: true,
},
};
const babelAST = parser.parse(sourceCode, {
const babelAST = HermesParser.parse(sourceCode, {
babel: true,
sourceFilename: filename,
plugins: ["jsx", "flow"],
sourceType: "module",
});
if (babelAST != null) {
@@ -0,0 +1,12 @@
// v0.12.1
declare module "hermes-parser" {
type HermesParserOptions = {
babel: boolean;
allowReturnOutsideFunction: boolean;
flow: "all" | "detect";
sourceFilename: string | null;
sourceType: "module" | "script" | "unambiguous";
tokens: boolean;
};
export function parse(code: string, options: Partial<HermesParserOptions>);
}
+12
View File
@@ -5572,6 +5572,11 @@ hermes-eslint@^0.9.0:
hermes-estree "0.9.0"
hermes-parser "0.9.0"
hermes-estree@0.12.1:
version "0.12.1"
resolved "https://registry.yarnpkg.com/hermes-estree/-/hermes-estree-0.12.1.tgz#74901ee351387fecbf3c683c90b1fa7d22f1c6f0"
integrity sha512-IWnP3rEZnuEq64IGM/sNsp+QCQcCAAu5TMallJ7bpUw0YUfk5q6cA7tvBGo/D0kGyo5jASc4Yp/CQCsLSSMfGQ==
hermes-estree@0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/hermes-estree/-/hermes-estree-0.9.0.tgz#026e0abe6db1dcf50a81a79014b779a83db3b814"
@@ -5584,6 +5589,13 @@ hermes-parser@0.9.0:
dependencies:
hermes-estree "0.9.0"
hermes-parser@^0.12.1:
version "0.12.1"
resolved "https://registry.yarnpkg.com/hermes-parser/-/hermes-parser-0.12.1.tgz#e60595f05ecd13026c614ca5d9db2eaefe971301"
integrity sha512-53aep6osCq1GiSIlbe7ltPD9v0GeAUtGlaMhgKexGjePoI66GnalLR5aPeuIZbExBQAb+af/kiXT3yxBweuXUA==
dependencies:
hermes-estree "0.12.1"
hmac-drbg@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"