Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

// @ts-ignore

Check failure on line 8 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
import {NodePath} from '@babel/core';
// @ts-ignore

Check failure on line 10 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
import * as t from '@babel/types';
import {
CompilerError,
Expand Down Expand Up @@ -265,7 +267,9 @@
break;
}
default: {
// @ts-ignore

Check failure on line 270 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
assertExhaustive(
// @ts-ignore

Check failure on line 272 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
originalFn.node,
`Creating unhandled function: ${originalFn.node}`,
);
Expand Down Expand Up @@ -321,7 +325,9 @@
return insertedFuncDecl;
}
default: {
// @ts-ignore

Check failure on line 328 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
assertExhaustive(
// @ts-ignore

Check failure on line 330 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
originalFn,
`Inserting unhandled function: ${originalFn}`,
);
Expand Down Expand Up @@ -961,10 +967,13 @@
return componentSyntaxType;
}
case 'all': {
// @ts-ignore

Check failure on line 970 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
return getComponentOrHookLike(fn, hookPattern) ?? 'Other';
}
default: {
// @ts-ignore

Check failure on line 974 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
assertExhaustive(
// @ts-ignore

Check failure on line 976 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
pass.opts.compilationMode,
`Unexpected compilationMode \`${pass.opts.compilationMode}\``,
);
Expand Down Expand Up @@ -1125,6 +1134,7 @@
} else if (annot.type === 'Noop') {
return true;
} else {
// @ts-ignore

Check failure on line 1137 in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
assertExhaustive(annot, `Unexpected annotation node \`${annot}\``);
}
}
Expand Down Expand Up @@ -1398,6 +1408,23 @@
*/
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);
}
}
}
}
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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',
},
],
};
2 changes: 1 addition & 1 deletion flow-typed/npm/minimist_v1.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare module 'minimist' {
string?: string | Array<string>,
boolean?: boolean | string | Array<string>,
alias?: {[arg: string]: string | Array<string>, ...},
default?: {[arg: string]: any, ...},
default?: {[arg: string]: any, },
stopEarly?: boolean,
// TODO: Strings as keys don't work...
// '--'? boolean,
Expand Down
Loading