Skip to content

[compiler][ez] Stop bailing out early for hoisted gated functions#32597

Merged
mofeiZ merged 1 commit into
mainfrom
pr32597
Mar 13, 2025
Merged

[compiler][ez] Stop bailing out early for hoisted gated functions#32597
mofeiZ merged 1 commit into
mainfrom
pr32597

Conversation

@mofeiZ
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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

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.

3 participants