Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] Run prettier #29214

Merged
merged 10 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 8 additions & 10 deletions compiler/apps/playground/components/Editor/EditorImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
} from "./Output";

function parseFunctions(
source: string,
source: string
): Array<
NodePath<
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
Expand Down Expand Up @@ -148,7 +148,7 @@ function isHookName(s: string): boolean {
}

function getReactFunctionType(
id: NodePath<t.Identifier | null | undefined>,
id: NodePath<t.Identifier | null | undefined>
): ReactFunctionType {
if (id && id.node && id.isIdentifier()) {
if (isHookName(id.node.name)) {
Expand Down Expand Up @@ -189,7 +189,7 @@ function compile(source: string): CompilerOutput {
severity: ErrorSeverity.Todo,
loc: fn.node.loc ?? null,
suggestions: null,
}),
})
);
continue;
}
Expand All @@ -205,7 +205,7 @@ function compile(source: string): CompilerOutput {
"_c",
null,
null,
null,
null
)) {
const fnName = fn.node.id?.name ?? null;
switch (result.kind) {
Expand Down Expand Up @@ -274,7 +274,7 @@ function compile(source: string): CompilerOutput {
reason: `Unexpected failure when transforming input! ${err}`,
loc: null,
suggestions: null,
}),
})
);
}
}
Expand All @@ -291,7 +291,7 @@ export default function Editor() {
const { enqueueSnackbar } = useSnackbar();
const compilerOutput = useMemo(
() => compile(deferredStore.source),
[deferredStore.source],
[deferredStore.source]
);

useMountEffect(() => {
Expand All @@ -305,7 +305,7 @@ export default function Editor() {
...createMessage(
"Bad URL - fell back to the default Playground.",
MessageLevel.Info,
MessageSource.Playground,
MessageSource.Playground
),
});
mountStore = defaultStore;
Expand All @@ -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/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function Input({ errors }: Props) {
allowSyntheticDefaultImports: true,
};
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(
tscOptions,
tscOptions
);
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
...tscOptions,
Expand Down
18 changes: 9 additions & 9 deletions compiler/apps/playground/components/Editor/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async function tabify(source: string, compilerOutput: CompilerOutput) {
output={text}
diff={lastPassOutput ?? null}
showInfoPanel={true}
></TextTabContent>,
></TextTabContent>
);
lastPassOutput = text;
}
Expand All @@ -122,7 +122,7 @@ async function tabify(source: string, compilerOutput: CompilerOutput) {
output={code}
diff={null}
showInfoPanel={false}
></TextTabContent>,
></TextTabContent>
);
if (sourceMapUrl) {
reorderedTabs.set(
Expand All @@ -133,7 +133,7 @@ async function tabify(source: string, compilerOutput: CompilerOutput) {
className="w-full h-monaco_small sm:h-monaco"
title="Generated Code"
/>
</>,
</>
);
}
}
Expand All @@ -145,16 +145,16 @@ async function tabify(source: string, compilerOutput: CompilerOutput) {

async function codegen(
ast: t.Program,
source: string,
source: string
): Promise<{ code: any; sourceMapUrl: string | null }> {
const generated = generate(
ast,
{ sourceMaps: true, sourceFileName: "input.js" },
source,
source
);
const sourceMapUrl = getSourceMapUrl(
generated.code,
JSON.stringify(generated.map),
JSON.stringify(generated.map)
);
const codegenOutput = await prettier.format(generated.code, {
semi: true,
Expand All @@ -172,14 +172,14 @@ function getSourceMapUrl(code: string, map: string): string | null {
code = utf16ToUTF8(code);
map = utf16ToUTF8(map);
return `https://evanw.github.io/source-map-visualization/#${btoa(
`${code.length}\0${code}${map.length}\0${map}`,
`${code.length}\0${code}${map.length}\0${map}`
)}`;
}

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(),
() => new Map()
);
useEffect(() => {
tabify(store.source, compilerOutput).then((tabs) => {
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
2 changes: 1 addition & 1 deletion compiler/apps/playground/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function Header() {
<Logo
className={clsx(
"w-8 h-8 text-link",
process.env.NODE_ENV === "development" && "text-yellow-600",
process.env.NODE_ENV === "development" && "text-yellow-600"
)}
/>
<p className="hidden select-none sm:block">React Compiler Playground</p>
Expand Down
2 changes: 1 addition & 1 deletion compiler/apps/playground/components/Icons/IconGitHub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export const IconGitHub = memo<JSX.IntrinsicElements["svg"]>(
<path d="M10 0a10 10 0 0 0-3.16 19.49c.5.1.68-.22.68-.48l-.01-1.7c-2.78.6-3.37-1.34-3.37-1.34-.46-1.16-1.11-1.47-1.11-1.47-.9-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.9 1.52 2.34 1.08 2.91.83.1-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.1.39-1.99 1.03-2.69a3.6 3.6 0 0 1 .1-2.64s.84-.27 2.75 1.02a9.58 9.58 0 0 1 5 0c1.91-1.3 2.75-1.02 2.75-1.02.55 1.37.2 2.4.1 2.64.64.7 1.03 1.6 1.03 2.69 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85l-.01 2.75c0 .26.18.58.69.48A10 10 0 0 0 10 0"></path>
</svg>
);
},
}
);
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MarkerSeverity, type editor } from "monaco-editor";

function mapReactCompilerSeverityToMonaco(
level: ErrorSeverity,
monaco: Monaco,
monaco: Monaco
): MarkerSeverity {
switch (level) {
case ErrorSeverity.Todo:
Expand All @@ -26,7 +26,7 @@ function mapReactCompilerSeverityToMonaco(

function mapReactCompilerDiagnosticToMonacoMarker(
detail: CompilerErrorDetail,
monaco: Monaco,
monaco: Monaco
): editor.IMarkerData | null {
if (detail.loc == null || typeof detail.loc === "symbol") {
return null;
Expand Down Expand Up @@ -70,7 +70,7 @@ export function renderReactCompilerMarkers({
marker.startLineNumber,
marker.startColumn,
marker.endLineNumber,
marker.endColumn,
marker.endColumn
),
options: {
isWholeLine: true,
Expand All @@ -83,7 +83,7 @@ export function renderReactCompilerMarkers({
monaco.editor.setModelMarkers(model, "owner", []);
decorations = model.deltaDecorations(
model.getAllDecorations().map((d) => d.id),
[],
[]
);
}
}
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";
1 change: 0 additions & 1 deletion 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 Down
4 changes: 2 additions & 2 deletions compiler/apps/playground/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ const nextConfig = {
new MonacoWebpackPlugin({
languages: ["typescript", "javascript"],
filename: "static/[name].worker.js",
}),
})
);
}

config.resolve.alias = {
...config.resolve.alias,
"react-compiler-runtime": path.resolve(
__dirname,
"../../packages/react-compiler-runtime",
"../../packages/react-compiler-runtime"
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type ReactiveInstructionStatement = {
};

export type ReactiveTerminalStatement<
Tterminal extends ReactiveTerminal = ReactiveTerminal
Tterminal extends ReactiveTerminal = ReactiveTerminal,
> = {
kind: "terminal";
terminal: Tterminal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ export function mapTerminalSuccessors(

export function terminalHasFallthrough<
T extends Terminal,
U extends T & { fallthrough: BlockId }
U extends T & { fallthrough: BlockId },
>(terminal: T): terminal is U {
switch (terminal.kind) {
case "maybe-throw":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export type Transformed<T> =
| { kind: "replace-many"; value: Array<T> };

export class ReactiveFunctionTransform<
TState = void
TState = void,
> extends ReactiveFunctionVisitor<TState> {
override traverseBlock(block: ReactiveBlock, state: TState): void {
let nextBlock: ReactiveBlock | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export const FIXTURE_ENTRYPOINT = {
## Code

```javascript
import { c as _c } from "react/compiler-runtime";
/**
import { c as _c } from "react/compiler-runtime"; /**
* This is a weird case as data has type `BuiltInMixedReadonly`.
* The only scoped value we currently infer in this program is the
* PropertyLoad `data?.toString`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function getNativeLogFunction(level) {
INSPECTOR_LEVELS[logLevel],
str,
[].slice.call(arguments),
INSPECTOR_FRAMES_TO_SKIP
INSPECTOR_FRAMES_TO_SKIP,
);
}
if (groupStack.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Component() {
x = { f: () => console.log("original") };

(console.log("A"), x)[(console.log("B"), "f")](
(changeF(x), console.log("arg"), 1)
(changeF(x), console.log("arg"), 1),
);
$[1] = x;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export const FIXTURE_ENTRYPOINT = {
## Code

```javascript
import { c as _c } from "react/compiler-runtime";
/**
import { c as _c } from "react/compiler-runtime"; /**
* props.b *does* influence `a`
*/
function Component(props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export const FIXTURE_ENTRYPOINT = {
## Code

```javascript
import { c as _c } from "react/compiler-runtime";
/**
import { c as _c } from "react/compiler-runtime"; /**
* props.b does *not* influence `a`
*/
function ComponentA(props) {
Expand Down
Loading