@samitouri / QOS-React / commits / 8d234c64eb

[hir] Remove hermes parser

Exporting the hermes parser breaks the playground as the hermes parser can not work in the browser. No one is using this directly anyway -- snap and others bundle hermes parser on their own, so, let's remove it. ghstack-source-id: d448c346eb137f8ba6ada4ad113e41a90b29baff Pull Request resolved: https://github.com/facebook/react-forget/pull/2890

Sathya Gunsasekaran committed Apr 23, 2024 at 12:28 UTC 8d234c64eb2169b699503dea68899c7e4c408fba
6 files changed +16 -36
compiler/packages/babel-plugin-react-forget/package.json
-2
@@ -49,10 +49,8 @@
49 "babel-jest": "^29.0.3",
50 "babel-plugin-fbt": "^1.0.0",
51 "babel-plugin-fbt-runtime": "^1.0.0",
52 - "babel-plugin-syntax-hermes-parser": "^0.15.1",
52 "eslint": "8.27.0",
53 "glob": "^7.1.6",
55 - "hermes-parser": "^0.19.1",
54 "jest": "^29.0.3",
55 "jest-environment-jsdom": "^29.0.3",
56 "prettier": "2.8.8",
compiler/packages/babel-plugin-react-forget/src/Babel/BabelPlugin.ts
-2
@@ -5,8 +5,6 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -/// <reference path="./types.d.ts" />
9 -
8 import type * as BabelCore from "@babel/core";
9 import { compileProgram, parsePluginOptions } from "../Entrypoint";
10
compiler/packages/babel-plugin-react-forget/src/Babel/RunReactForgetBabelPlugin.ts
+5 -17
@@ -8,7 +8,6 @@
8 import type * as BabelCore from "@babel/core";
9 import { transformFromAstSync } from "@babel/core";
10 import * as BabelParser from "@babel/parser";
11 -import * as HermesParser from "hermes-parser";
11 import invariant from "invariant";
12 import type { PluginOptions } from "../Entrypoint";
13 import ReactForgetBabelPlugin from "./BabelPlugin";
@@ -21,22 +20,11 @@ export function runReactForgetBabelPlugin(
20 options: Partial<PluginOptions> | null,
21 includeAst: boolean = false
22 ): BabelCore.BabelFileResult {
24 - let ast;
25 - if (language === "flow") {
26 - ast = HermesParser.parse(text, {
27 - babel: true,
28 - flow: "all",
29 - sourceFilename: file,
30 - sourceType: "module",
31 - enableExperimentalComponentSyntax: true,
32 - });
33 - } else {
34 - ast = BabelParser.parse(text, {
35 - sourceFilename: file,
36 - plugins: ["typescript", "jsx"],
37 - sourceType: "module",
38 - });
39 - }
23 + const ast = BabelParser.parse(text, {
24 + sourceFilename: file,
25 + plugins: [language, "jsx"],
26 + sourceType: "module",
27 + });
28 const result = transformFromAstSync(ast, text, {
29 ast: includeAst,
30 filename: file,
compiler/packages/babel-plugin-react-forget/src/__tests__/Logger-test.ts
+10 -13
@@ -5,6 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 +import * as t from "@babel/types";
9 import invariant from "invariant";
10 import { runReactForgetBabelPlugin } from "../Babel/RunReactForgetBabelPlugin";
11 import type { Logger, LoggerEvent } from "../Entrypoint";
@@ -29,10 +30,8 @@ it("logs succesful compilation", () => {
30 expect(event.kind).toEqual("CompileSuccess");
31 invariant(event.kind === "CompileSuccess", "typescript be smarter");
32 expect(event.fnName).toEqual("Component");
32 - expect(event.fnLoc).toEqual({
33 - end: { column: 55, line: 1 },
34 - start: { column: 0, line: 1 },
35 - });
33 + expect(event.fnLoc?.end).toEqual({ column: 55, index: 55, line: 1 });
34 + expect(event.fnLoc?.start).toEqual({ column: 0, index: 0, line: 1 });
35 });
36
37 it("logs failed compilation", () => {
@@ -58,15 +57,13 @@ it("logs failed compilation", () => {
57 invariant(event.kind === "CompileError", "typescript be smarter");
58
59 expect(event.detail.severity).toEqual("InvalidReact");
61 - expect(event.detail.loc).toEqual({
62 - end: { column: 33, line: 1 },
63 - identifierName: "props",
64 - start: { column: 28, line: 1 },
65 - });
60 + //@ts-ignore
61 + const { start, end, identifierName } = event.detail.loc as t.SourceLocation;
62 + expect(start).toEqual({ column: 28, index: 28, line: 1 });
63 + expect(end).toEqual({ column: 33, index: 33, line: 1 });
64 + expect(identifierName).toEqual("props");
65
66 // Make sure event.fnLoc is different from event.detail.loc
68 - expect(event.fnLoc).toEqual({
69 - end: { column: 70, line: 1 },
70 - start: { column: 0, line: 1 },
71 - });
67 + expect(event.fnLoc?.start).toEqual({ column: 0, index: 0, line: 1 });
68 + expect(event.fnLoc?.end).toEqual({ column: 70, index: 70, line: 1 });
69 });
compiler/packages/eslint-plugin-react-compiler/package.json
+1
@@ -23,6 +23,7 @@
23 "babel-jest": "^29.0.3",
24 "eslint": "8.57.0",
25 "hermes-eslint": "^0.17.1",
26 + "hermes-parser": "^0.19.1",
27 "jest": "^29.5.0"
28 },
29 "engines": {
compiler/packages/eslint-plugin-react-compiler/src/types/hermes-parser.d.ts renamed
-2
@@ -5,8 +5,6 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -declare module "@babel/plugin-syntax-jsx";
9 -
8 // v0.17.1
9 declare module "hermes-parser" {
10 type HermesParserOptions = {