Skip to content
Closed
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,12 +267,14 @@
break;
}
default: {
// @ts-ignore
assertExhaustive(
// @ts-ignore
originalFn.node,
`Creating unhandled function: ${originalFn.node}`,
);

Check failure on line 275 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
}
}

Check failure on line 277 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
// Avoid visiting the new transformed version
return transformedFn;
}
Expand Down Expand Up @@ -321,12 +325,14 @@
return insertedFuncDecl;
}
default: {
// @ts-ignore
assertExhaustive(
// @ts-ignore
originalFn,
`Inserting unhandled function: ${originalFn}`,
);

Check failure on line 333 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
}
}

Check failure on line 335 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
}

const DEFAULT_ESLINT_SUPPRESSIONS = [
Expand Down Expand Up @@ -961,10 +967,13 @@
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}\``,
);
Expand All @@ -990,13 +999,13 @@
importedName = imported.node.name;
} else if (imported.isStringLiteral()) {
importedName = imported.node.value;
}

Check failure on line 1002 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
if (
importedName === 'c' &&
path.parentPath.isImportDeclaration() &&
path.parentPath.get('source').node.value === moduleName

Check failure on line 1006 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
) {
hasUseMemoCache = true;

Check failure on line 1008 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
}
},
});
Expand Down Expand Up @@ -1125,6 +1134,7 @@
} else if (annot.type === 'Noop') {
return true;
} else {
// @ts-ignore
assertExhaustive(annot, `Unexpected annotation node \`${annot}\``);
}
}
Expand Down Expand Up @@ -1156,7 +1166,7 @@
}
return false;
}

Check failure on line 1169 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
/*
* Adapted from the ESLint rule at
* https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js#L90-L103
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);
Comment on lines +1415 to +1417

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: scope.getFunctionParent() returns a Scope, but getFunctionName() expects a NodePath. Should be parentFunction.path

Suggested change
const parentFunction = scope.getFunctionParent();
if (parentFunction !== null) {
const parentFnName = getFunctionName(parentFunction);
const parentFunction = scope.getFunctionParent();
if (parentFunction !== null) {
const parentFnName = getFunctionName(parentFunction.path);
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts
Line: 1415:1417

Comment:
**syntax:** `scope.getFunctionParent()` returns a `Scope`, but `getFunctionName()` expects a `NodePath`. Should be `parentFunction.path`

```suggestion
        const parentFunction = scope.getFunctionParent();
        if (parentFunction !== null) {
          const parentFnName = getFunctionName(parentFunction.path);
```

How can I resolve this? If you propose a fix, please make it concise.

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