Skip to content

Conversation

@mofeiZ
Copy link
Contributor

@mofeiZ mofeiZ commented Mar 13, 2025

Comment on lines 25 to 32
CompilerError.throwTodo({
reason: `Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting`,
description: `Rewrite the reference to ${fnPath.node.id?.name ?? 'this function'} to not rely on hoisting to fix this issue`,
loc: fnPath.node.loc ?? null,
suggestions: null,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

#32598 replaces this bailout with special handling

});
} else {
fnPath.replaceWith(gatingExpression);
const gatingExpression = t.conditionalExpression(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(unchanged)

parsedOptions[key] = parseTargetConfig(value);
break;
}
case 'gating': {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved gating config parsing to BabelPlugin entrypoint -- now it's unconditional and eager like the rest of our config parsing / validation. Previously, we only tried to parse gating if we had successful compilation events.

return;
}

let gating: null | {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes in this file are all code movement.

  • tryParseExternalFunction is moved to parsePluginOptions, which runs before this function
  • collect referencedBeforeDeclared set here instead eagerly bailing out. This is to prepare for the next PR [compiler] Avoid bailouts when inserting gating #32598. (Also happy to merge these into a single changeset if that's easier to review)

Comment on lines 24 to 32
if (referencedBeforeDeclaration) {
CompilerError.throwTodo({
reason: `Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting`,
description: `Rewrite the reference to ${fnPath.node.id?.name ?? 'this function'} to not rely on hoisting to fix this issue`,
loc: fnPath.node.loc ?? null,
suggestions: null,
});
Copy link
Member

Choose a reason for hiding this comment

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

Small nit; what do you think about moving the throw to the callsite instead of having the boolean arg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#32511 replaces this throw, so this is very temporary

@mofeiZ mofeiZ merged commit 93b61fc into main Mar 13, 2025
23 of 24 checks passed
@poteto poteto deleted the pr32597 branch March 26, 2025 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants