Skip to content

Commit

Permalink
[compiler] Run prettier, fix snap
Browse files Browse the repository at this point in the history
This commit will be ignored in .git-blame-ignore-revs

ghstack-source-id: ac728261488a49034dd2b8f23d4b58fd23c87f46
Pull Request resolved: facebook/react#29214
  • Loading branch information
poteto committed May 22, 2024
1 parent 8ef7003 commit 24050d2
Show file tree
Hide file tree
Showing 202 changed files with 1,203 additions and 1,181 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/compiler-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ jobs:
run: echo "matrix=$(find packages -mindepth 1 -maxdepth 1 -type d | sed 's!packages/!!g' | tr '\n' ',' | sed s/.$// | jq -Rsc '. / "," - [""]')" >> $GITHUB_OUTPUT

# Hardcoded to improve parallelism for babel-plugin-react-compiler
prettier:
name: Run prettier
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: compiler/yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('compiler/**/yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: yarn prettier:ci

# Hardcoded to improve parallelism
lint:
name: Lint babel-plugin-react-compiler
runs-on: ubuntu-latest
Expand All @@ -40,10 +59,9 @@ jobs:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('compiler/**/yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: yarn workspace babel-plugin-react-compiler prettier:ci
- run: yarn workspace babel-plugin-react-compiler lint

# Hardcoded to improve parallelism for babel-plugin-react-compiler
# Hardcoded to improve parallelism
jest:
name: Jest babel-plugin-react-compiler
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion compiler/apps/playground/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/


/**
* Sync from <https://github.com/reactjs/reactjs.org/blob/main/beta/colors.js>.
*/
Expand Down
4 changes: 1 addition & 3 deletions compiler/apps/playground/components/Editor/EditorImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ export default function Editor() {
return (
<>
<div className="relative flex basis top-14">
<div
className={clsx("relative sm:basis-1/4")}
>
<div className={clsx("relative sm:basis-1/4")}>
<Input
errors={
compilerOutput.kind === "err" ? compilerOutput.error.details : []
Expand Down
2 changes: 1 addition & 1 deletion compiler/apps/playground/components/Editor/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function getSourceMapUrl(code: string, map: string): string | null {
}

function Output({ store, compilerOutput }: Props) {
const [tabsOpen, setTabsOpen] = useState<Set<string>>(() => new Set(['JS']));
const [tabsOpen, setTabsOpen] = useState<Set<string>>(() => new Set(["JS"]));
const [tabs, setTabs] = useState<Map<string, React.ReactNode>>(
() => new Map(),
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/apps/playground/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ const Editor = dynamic(() => import("./EditorImpl"), {
ssr: false,
});

export default Editor;
export default Editor;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/


import type { EditorProps } from "@monaco-editor/react";

export const monacoOptions: Partial<EditorProps["options"]> = {
Expand Down
1 change: 0 additions & 1 deletion compiler/apps/playground/components/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/


// https://github.com/reactjs/reactjs.org/blob/main/beta/src/components/Logo.tsx

export default function Logo(props: JSX.IntrinsicElements["svg"]) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/apps/playground/components/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const Message = forwardRef<HTMLDivElement, MessageProps>(
) : null}
</SnackbarContent>
);
}
},
);

Message.displayName = "MessageComponent";
Expand Down
1 change: 0 additions & 1 deletion compiler/apps/playground/components/StoreContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/


import type { Dispatch, ReactNode } from "react";
import { useReducer } from "react";
import createContext from "../lib/createContext";
Expand Down
4 changes: 2 additions & 2 deletions compiler/apps/playground/components/TabbedWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function TabbedWindowItem({
title="Minimize tab"
aria-label="Minimize tab"
onClick={toggleTabs}
className={`p-4 duration-150 ease-in border-b cursor-pointer border-grey-200 ${hasChanged ? 'font-bold' : 'font-light'} text-secondary hover:text-link`}
className={`p-4 duration-150 ease-in border-b cursor-pointer border-grey-200 ${hasChanged ? "font-bold" : "font-light"} text-secondary hover:text-link`}
>
- {name}
</h2>
Expand All @@ -91,7 +91,7 @@ function TabbedWindowItem({
aria-label={`Expand compiler tab: ${name}`}
style={{ transform: "rotate(90deg) translate(-50%)" }}
onClick={toggleTabs}
className={`flex-grow-0 w-5 transition-colors duration-150 ease-in ${hasChanged ? 'font-bold' : 'font-light'} text-secondary hover:text-link`}
className={`flex-grow-0 w-5 transition-colors duration-150 ease-in ${hasChanged ? "font-bold" : "font-light"} text-secondary hover:text-link`}
>
{name}
</button>
Expand Down
1 change: 0 additions & 1 deletion compiler/apps/playground/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/


export { default as Editor } from "./Editor";
export { default as Header } from "./Header";
export { StoreProvider } from "./StoreContext";
1 change: 0 additions & 1 deletion compiler/apps/playground/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
* LICENSE file in the root directory of this source tree.
*/


export { default as useMountEffect } from "./useMountEffect";
1 change: 0 additions & 1 deletion compiler/apps/playground/hooks/useMountEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/


import type { EffectCallback } from "react";
import { useEffect } from "react";

Expand Down
1 change: 0 additions & 1 deletion compiler/apps/playground/lib/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/


import React from "react";

/**
Expand Down
1 change: 0 additions & 1 deletion compiler/apps/playground/lib/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
* LICENSE file in the root directory of this source tree.
*/


export * from "./messages";
export * from "./store";
3 changes: 1 addition & 2 deletions compiler/apps/playground/lib/stores/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/


export enum MessageSource {
Babel,
Forget,
Expand All @@ -28,7 +27,7 @@ export interface Message {
export function createMessage(
message: string,
level: MessageLevel,
source: MessageSource
source: MessageSource,
): Message {
const [title, ...body] = message.split("\n");
const codeframe = body.length > 0 ? body.join("\n") : undefined;
Expand Down
6 changes: 3 additions & 3 deletions compiler/apps/playground/scripts/downloadFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const { execSync } = require("child_process");
// So that we don't need to check them into the repo.
// See https://github.com/reactjs/reactjs.org/blob/main/beta/scripts/downloadFonts.js.
execSync(
"curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Lt.woff2 --output public/fonts/Optimistic_Display_W_Lt.woff2"
"curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Lt.woff2 --output public/fonts/Optimistic_Display_W_Lt.woff2",
);
execSync(
"curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Md.woff2 --output public/fonts/Optimistic_Display_W_Md.woff2"
"curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Md.woff2 --output public/fonts/Optimistic_Display_W_Md.woff2",
);
execSync(
"curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Bd.woff2 --output public/fonts/Optimistic_Display_W_Bd.woff2"
"curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Bd.woff2 --output public/fonts/Optimistic_Display_W_Bd.woff2",
);
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const DEV_ROLLUP_CONFIG = {
*/
"use no memo";
`
`,
),
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { NodePath } from "@babel/core";
import * as t from "@babel/types";

export default function AnnotateReactCodeBabelPlugin(
_babel: typeof BabelCore
_babel: typeof BabelCore,
): BabelCore.PluginObj {
return {
name: "annotate-react-code",
Expand Down Expand Up @@ -64,15 +64,15 @@ function buildTypeOfReactForget(): t.Statement {
t.identifier("Symbol"),
t.identifier("for"),
false,
false
false,
),
[t.stringLiteral("react_forget")]
[t.stringLiteral("react_forget")],
),
true,
false
false,
),
true
)
true,
),
);
}

Expand All @@ -89,7 +89,7 @@ type BabelFn =
| NodePath<t.ArrowFunctionExpression>;

export function isComponentDeclaration(
node: t.FunctionDeclaration
node: t.FunctionDeclaration,
): node is ComponentDeclaration {
return Object.prototype.hasOwnProperty.call(node, "__componentDeclaration");
}
Expand All @@ -101,7 +101,7 @@ export function isComponentDeclaration(
function isComponentOrHookLike(
node: NodePath<
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
>
>,
): boolean {
const functionName = getFunctionName(node);
// Check if the name is component or hook like:
Expand Down Expand Up @@ -197,7 +197,7 @@ function isMemoCallback(path: NodePath<t.Expression>): boolean {

function isReactAPI(
path: NodePath<t.Expression | t.PrivateName | t.V8IntrinsicIdentifier>,
functionName: string
functionName: string,
): boolean {
const node = path.node;
return (
Expand Down Expand Up @@ -239,7 +239,7 @@ function callsHooksOrCreatesJsx(node: NodePath<t.Node>): boolean {
function getFunctionName(
path: NodePath<
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
>
>,
): NodePath<t.Expression> | null {
if (path.isFunctionDeclaration()) {
const id = path.get("id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const FIXTURES_DIR = path.join(
"__tests__",
"fixtures",
"compiler",
"rules-of-hooks"
"rules-of-hooks",
);

const PRETTIER_OPTIONS = prettier.resolveConfig.sync(FIXTURES_DIR, {
Expand Down Expand Up @@ -53,7 +53,7 @@ for (const fixture of fixtures) {
environment: {
validateHooksUsage: false,
},
}
},
);
// Does the fixture pass with hooks validation enabled?
try {
Expand All @@ -65,7 +65,7 @@ for (const fixture of fixtures) {
environment: {
validateHooksUsage: true,
},
}
},
);
} catch (e) {
passes = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function makeSnapshotResolver(useForget) {
resolveTestPath: (snapshotFilePath, snapshotExtension) =>
snapshotFilePath.slice(
0,
-modeExtension.length - snapshotExtension.length
-modeExtension.length - snapshotExtension.length,
),

testPathForConsistencyCheck: "some/__tests__/example.test.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = (useForget: boolean) => {
* (see https://github.com/jestjs/jest/blob/v29.6.2/packages/babel-jest/src/index.ts#L84)
*/
compilerCacheKey: execSync(
"yarn --silent --cwd ../.. hash packages/babel-plugin-react-compiler/dist"
"yarn --silent --cwd ../.. hash packages/babel-plugin-react-compiler/dist",
).toString(),
transformOptionsCacheKey: forgetOptions,
e2eTransformerCacheKey,
Expand Down Expand Up @@ -169,7 +169,7 @@ function ReactForgetFunctionTransform() {
const filename = basename(state.file.opts.filename);
if (fn.node.loc && fn.node.id) {
console.log(
` Compiling ${filename}:${fn.node.loc.start.line}:${fn.node.loc.start.column} ${fn.node.id.name}`
` Compiling ${filename}:${fn.node.loc.start.line}:${fn.node.loc.start.column} ${fn.node.id.name}`,
);
} else {
console.log(` Compiling ${filename} ${fn.node.id?.name}`);
Expand All @@ -183,7 +183,7 @@ function ReactForgetFunctionTransform() {
"_c",
null,
null,
null
null,
);
compiledFns.add(compiled);

Expand All @@ -192,7 +192,7 @@ function ReactForgetFunctionTransform() {
compiled.params,
compiled.body,
compiled.generator,
compiled.async
compiled.async,
);
fn.replaceWith(fun);
fn.skip();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
* @returns
*/
export default function BabelPluginReactCompiler(
_babel: typeof BabelCore
_babel: typeof BabelCore,
): BabelCore.PluginObj {
return {
name: "react-forget",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function runBabelPluginReactCompiler(
file: string,
language: "flow" | "typescript",
options: Partial<PluginOptions> | null,
includeAst: boolean = false
includeAst: boolean = false,
): BabelCore.BabelFileResult {
const ast = BabelParser.parse(text, {
sourceFilename: file,
Expand All @@ -39,7 +39,7 @@ export function runBabelPluginReactCompiler(
});
invariant(
result?.code != null,
`Expected BabelPluginReactForget to codegen successfully, got: ${result}`
`Expected BabelPluginReactForget to codegen successfully, got: ${result}`,
);
return result;
}
Loading

0 comments on commit 24050d2

Please sign in to comment.