OptimizePropsMethodCalls.ts — react Source File
Architecture documentation for OptimizePropsMethodCalls.ts, a typescript file in the react codebase. 1 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 8eda52b7_ff03_211a_9817_be340ccb9c33["OptimizePropsMethodCalls.ts"] 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] 8eda52b7_ff03_211a_9817_be340ccb9c33 --> 0423f759_97e0_9101_4634_ed555abc5ca9 e3cfc07a_10c8_5dcd_e270_e8e14c29309b["Pipeline.ts"] e3cfc07a_10c8_5dcd_e270_e8e14c29309b --> 8eda52b7_ff03_211a_9817_be340ccb9c33 style 8eda52b7_ff03_211a_9817_be340ccb9c33 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {HIRFunction, isPropsType} from '../HIR';
/**
* Converts method calls into regular calls where the receiver is the props object:
*
* Example:
*
* ```
* // INPUT
* props.foo();
*
* // OUTPUT
* const t0 = props.foo;
* t0();
* ```
*
* Counter example:
*
* Here the receiver is `props.foo`, not the props object, so we don't rewrite it:
*
* // INPUT
* props.foo.bar();
*
* // OUTPUT
* props.foo.bar();
* ```
*/
export function optimizePropsMethodCalls(fn: HIRFunction): void {
for (const [, block] of fn.body.blocks) {
for (let i = 0; i < block.instructions.length; i++) {
const instr = block.instructions[i]!;
if (
instr.value.kind === 'MethodCall' &&
isPropsType(instr.value.receiver.identifier)
) {
instr.value = {
kind: 'CallExpression',
callee: instr.value.property,
args: instr.value.args,
loc: instr.value.loc,
};
}
}
}
}
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does OptimizePropsMethodCalls.ts do?
OptimizePropsMethodCalls.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Optimization subdomain.
What functions are defined in OptimizePropsMethodCalls.ts?
OptimizePropsMethodCalls.ts defines 1 function(s): optimizePropsMethodCalls.
What does OptimizePropsMethodCalls.ts depend on?
OptimizePropsMethodCalls.ts imports 1 module(s): index.ts.
What files import OptimizePropsMethodCalls.ts?
OptimizePropsMethodCalls.ts is imported by 1 file(s): Pipeline.ts.
Where is OptimizePropsMethodCalls.ts in the architecture?
OptimizePropsMethodCalls.ts is located at compiler/packages/babel-plugin-react-compiler/src/Optimization/OptimizePropsMethodCalls.ts (domain: BabelCompiler, subdomain: Optimization, directory: compiler/packages/babel-plugin-react-compiler/src/Optimization).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free