dillon1000/react

Commit

[compiler] Improve name hints for outlined functions (#34434)

The previous PR added name hints for anonymous functions, but didn't
handle the case of outlined functions. Here we do some cleanup around
function `id` and name hints:
* Make `HIRFunction.id` a ValidatedIdentifierName, which involved some
cleanup of the validation helpers
* Add `HIRFunction.nameHint: string` as a place to store the generated
name hints which are not valid identifiers
* Update Codegen to always use the `id` as the actual function name, and
only use nameHint as part of generating the object+property wrapper for
debug purposes.

This ensures we don't conflate synthesized hints with real function
names. Then, we also update OutlineFunctions to use the function name
_or_ the nameHint as the input to generating a unique identifier. This
isn't quite as nice as the object form since we lose our formatting, but
it's a simple step that gives more context to the developer than `_temp`
does.

Switching to output the object+property lookup form for outlined
functions is a bit more involved, let's do that in a follow-up.
Browse files
Changed paths12 files
First-parent comparison
M compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Pipeline.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/Optimization/LowerContextAccess.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/Optimization/OutlineFunctions.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/Optimization/OutlineJsx.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/Transform/NameAnonymousFunctions.ts ModifiedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/name-anonymous-functions-outline.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/name-anonymous-functions-outline.js Added
Patch

Files changed

Rendering syntax-highlighted changes…