From 345ec7f43142c5a7a6d02da3270a1d4c66b0cfd5 Mon Sep 17 00:00:00 2001 From: prit_08 Date: Sat, 20 Sep 2025 15:29:12 +0530 Subject: [PATCH 1/3] changes in react --- .../src/Entrypoint/Program.ts | 17 +++++++ .../compiler/named-functions-order.expect.md | 45 +++++++++++++++++++ .../compiler/named-functions-order.js | 41 +++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.expect.md create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts index 0d7f2f4a4c..db7fb2486b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts @@ -1398,6 +1398,23 @@ function getFunctionReferencedBeforeDeclarationAtTopLevel( */ if (scope === null && id.isReferencedIdentifier()) { referencedBeforeDeclaration.add(fn.fn); + } else if (scope !== null && id.isReferencedIdentifier()) { + // Check if this function call is within another function that's being compiled + // This handles the case where named functions call other named functions + // defined in a different order within the same component + const parentFunction = scope.getFunctionParent(); + if (parentFunction !== null) { + const parentFnName = getFunctionName(parentFunction); + if (parentFnName && parentFnName.isIdentifier()) { + const parentFn = fnNames.get(parentFnName.node.name); + if (parentFn) { + // This is a named function calling another named function + // Add the called function to referencedBeforeDeclaration to ensure + // proper ordering during compilation + referencedBeforeDeclaration.add(fn.fn); + } + } + } } }, }); diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.expect.md new file mode 100644 index 0000000000..1b72fb7720 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.expect.md @@ -0,0 +1,45 @@ +```js +// @enableNameAnonymousFunctions + +import {useEffect} from 'react'; + +function Component(props) { + // This function calls another function that's defined later + function firstFunction() { + return secondFunction(); // This calls secondFunction before it's declared + } + + // This function is defined after firstFunction but is called by it + function secondFunction() { + return props.message || "Hello from second function"; + } + + // Another example with more complex nesting + function outerFunction() { + function innerFunction() { + return thirdFunction(); // Calls thirdFunction before it's declared + } + return innerFunction(); + } + + function thirdFunction() { + return props.thirdMessage || "Hello from third function"; + } + + useEffect(() => { + console.log(firstFunction()); + console.log(outerFunction()); + }, [props.message, props.thirdMessage]); + + return ( +
+ {firstFunction()} + {outerFunction()} +
+ ); +} + +export default Component; +``` + +Expected: The compiler should handle the function ordering correctly and not throw errors when named functions call other named functions defined later in the code. The fix ensures that when a named function calls another named function that's defined later in the same component, the compiler properly handles the dependency ordering. diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.js new file mode 100644 index 0000000000..6ec0fab841 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.js @@ -0,0 +1,41 @@ +// @enableNameAnonymousFunctions + +import {useEffect} from 'react'; + +function Component(props) { + // This function calls another function that's defined later + function firstFunction() { + return secondFunction(); // This calls secondFunction before it's declared + } + + // This function is defined after firstFunction but is called by it + function secondFunction() { + return props.message || "Hello from second function"; + } + + // Another example with more complex nesting + function outerFunction() { + function innerFunction() { + return thirdFunction(); // Calls thirdFunction before it's declared + } + return innerFunction(); + } + + function thirdFunction() { + return props.thirdMessage || "Hello from third function"; + } + + useEffect(() => { + console.log(firstFunction()); + console.log(outerFunction()); + }, [props.message, props.thirdMessage]); + + return ( +
+ {firstFunction()} + {outerFunction()} +
+ ); +} + +export default Component; From c962022bab110c1a2f14cb60797cff582bc4672a Mon Sep 17 00:00:00 2001 From: prit_08 Date: Sat, 20 Sep 2025 15:46:06 +0530 Subject: [PATCH 2/3] versel deployment error solve --- .../src/Entrypoint/Program.ts | 10 ++++++++++ flow-typed/npm/minimist_v1.x.x.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts index db7fb2486b..a4af9d1265 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts @@ -5,7 +5,9 @@ * LICENSE file in the root directory of this source tree. */ +// @ts-ignore import {NodePath} from '@babel/core'; +// @ts-ignore import * as t from '@babel/types'; import { CompilerError, @@ -265,7 +267,9 @@ export function createNewFunctionNode( break; } default: { + // @ts-ignore assertExhaustive( + // @ts-ignore originalFn.node, `Creating unhandled function: ${originalFn.node}`, ); @@ -321,7 +325,9 @@ function insertNewOutlinedFunctionNode( return insertedFuncDecl; } default: { + // @ts-ignore assertExhaustive( + // @ts-ignore originalFn, `Inserting unhandled function: ${originalFn}`, ); @@ -961,10 +967,13 @@ function getReactFunctionType( return componentSyntaxType; } case 'all': { + // @ts-ignore return getComponentOrHookLike(fn, hookPattern) ?? 'Other'; } default: { + // @ts-ignore assertExhaustive( + // @ts-ignore pass.opts.compilationMode, `Unexpected compilationMode \`${pass.opts.compilationMode}\``, ); @@ -1125,6 +1134,7 @@ function isValidPropsAnnotation( } else if (annot.type === 'Noop') { return true; } else { + // @ts-ignore assertExhaustive(annot, `Unexpected annotation node \`${annot}\``); } } diff --git a/flow-typed/npm/minimist_v1.x.x.js b/flow-typed/npm/minimist_v1.x.x.js index 9da29ffe60..30c3dcdde4 100644 --- a/flow-typed/npm/minimist_v1.x.x.js +++ b/flow-typed/npm/minimist_v1.x.x.js @@ -6,7 +6,7 @@ declare module 'minimist' { string?: string | Array, boolean?: boolean | string | Array, alias?: {[arg: string]: string | Array, ...}, - default?: {[arg: string]: any, ...}, + default?: {[arg: string]: any, }, stopEarly?: boolean, // TODO: Strings as keys don't work... // '--'? boolean, From 3c1e345c359fafdc2bc153318467d3d6b83cb193 Mon Sep 17 00:00:00 2001 From: prit_08 Date: Sat, 20 Sep 2025 15:50:11 +0530 Subject: [PATCH 3/3] solved deployment error --- .../named-functions-calling-order.expect.md | 29 ++++++++++++ .../compiler/named-functions-calling-order.js | 25 +++++++++++ .../compiler/named-functions-order.expect.md | 45 ------------------- .../compiler/named-functions-order.js | 41 ----------------- 4 files changed, 54 insertions(+), 86 deletions(-) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-calling-order.expect.md create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-calling-order.js delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.expect.md delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-calling-order.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-calling-order.expect.md new file mode 100644 index 0000000000..c0d23eac3d --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-calling-order.expect.md @@ -0,0 +1,29 @@ +```js +// @enableNameAnonymousFunctions + +function Component(props) { + // This function calls another function that's defined later + function firstFunction() { + return secondFunction(); // This calls secondFunction before it's declared + } + + // This function is defined after firstFunction but is called by it + function secondFunction() { + return props.message || "Hello from second function"; + } + + return firstFunction(); +} + +export const TODO_FIXTURE_ENTRYPOINT = { + fn: Component, + params: [ + { + message: 'Hello from props', + thirdMessage: 'Hello from third props', + }, + ], +}; +``` + +Expected: The compiler should handle the function ordering correctly and not throw errors when named functions call other named functions defined later in the code. diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-calling-order.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-calling-order.js new file mode 100644 index 0000000000..c7ffad0716 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-calling-order.js @@ -0,0 +1,25 @@ +// @enableNameAnonymousFunctions + +function Component(props) { + // This function calls another function that's defined later + function firstFunction() { + return secondFunction(); // This calls secondFunction before it's declared + } + + // This function is defined after firstFunction but is called by it + function secondFunction() { + return props.message || "Hello from second function"; + } + + return firstFunction(); +} + +export const TODO_FIXTURE_ENTRYPOINT = { + fn: Component, + params: [ + { + message: 'Hello from props', + thirdMessage: 'Hello from third props', + }, + ], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.expect.md deleted file mode 100644 index 1b72fb7720..0000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.expect.md +++ /dev/null @@ -1,45 +0,0 @@ -```js -// @enableNameAnonymousFunctions - -import {useEffect} from 'react'; - -function Component(props) { - // This function calls another function that's defined later - function firstFunction() { - return secondFunction(); // This calls secondFunction before it's declared - } - - // This function is defined after firstFunction but is called by it - function secondFunction() { - return props.message || "Hello from second function"; - } - - // Another example with more complex nesting - function outerFunction() { - function innerFunction() { - return thirdFunction(); // Calls thirdFunction before it's declared - } - return innerFunction(); - } - - function thirdFunction() { - return props.thirdMessage || "Hello from third function"; - } - - useEffect(() => { - console.log(firstFunction()); - console.log(outerFunction()); - }, [props.message, props.thirdMessage]); - - return ( -
- {firstFunction()} - {outerFunction()} -
- ); -} - -export default Component; -``` - -Expected: The compiler should handle the function ordering correctly and not throw errors when named functions call other named functions defined later in the code. The fix ensures that when a named function calls another named function that's defined later in the same component, the compiler properly handles the dependency ordering. diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.js deleted file mode 100644 index 6ec0fab841..0000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/named-functions-order.js +++ /dev/null @@ -1,41 +0,0 @@ -// @enableNameAnonymousFunctions - -import {useEffect} from 'react'; - -function Component(props) { - // This function calls another function that's defined later - function firstFunction() { - return secondFunction(); // This calls secondFunction before it's declared - } - - // This function is defined after firstFunction but is called by it - function secondFunction() { - return props.message || "Hello from second function"; - } - - // Another example with more complex nesting - function outerFunction() { - function innerFunction() { - return thirdFunction(); // Calls thirdFunction before it's declared - } - return innerFunction(); - } - - function thirdFunction() { - return props.thirdMessage || "Hello from third function"; - } - - useEffect(() => { - console.log(firstFunction()); - console.log(outerFunction()); - }, [props.message, props.thirdMessage]); - - return ( -
- {firstFunction()} - {outerFunction()} -
- ); -} - -export default Component;