dillon1000/react
Commit
Browse files Use single name resolver for nested functions
This is a prerequisite to inlining `useMemo()` lambdas so that we can better
optimize them. Nested functions are evaluated with a fresh HIRBuilder, which
means that they currently have their own `bindings` object for mapping
identifier instances to IdentifierIds. This means that identifier ids in a
closure are _always_ different that those outside the closure, even when they
refer to the same identifier:
```
function Component(props) {
props; // becomes e.g. props$1
const onClick = () => {
props // becomes e.g. props$2
};
}
```
For useMemo inlining this is problematic because we've lost the association that
these identifiers actually refer to the same thing. This PR changes that,
sharing the name resolution data structure between the top-level function and
any nested function expressions.Changed paths10 files
First-parent comparisoncompiler/forget/src/CompilerPipeline.ts ModifiedM compiler/forget/src/HIR/BuildHIR.ts ModifiedM compiler/forget/src/HIR/HIRBuilder.ts ModifiedM compiler/forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/capturing-function-member-expr-call.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/capturing-function-shadow-captured.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/inadvertent-mutability-readonly-lambda.expect.md ModifiedA compiler/forget/src/__tests__/fixtures/compiler/nested-function-shadowed-identifiers.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/nested-function-shadowed-identifiers.js AddedPatch
Files changed
Rendering syntax-highlighted changes…