Home / Function/ inlineJsxTransform() — react Function Reference

inlineJsxTransform() — react Function Reference

Architecture documentation for the inlineJsxTransform() function in InlineJsxTransform.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  2a874f47_71f2_6231_f751_4f1e63d38258["inlineJsxTransform()"]
  89892257_dbf9_0117_b9e8_961994e65882["InlineJsxTransform.ts"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|defined in| 89892257_dbf9_0117_b9e8_961994e65882
  5ca65604_fe7a_a934_9a93_7a441f7a7509["createTemporaryPlace()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| 5ca65604_fe7a_a934_9a93_7a441f7a7509
  a9b7ed44_3536_1cc9_0960_a44495056ef1["createPropsProperties()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| a9b7ed44_3536_1cc9_0960_a44495056ef1
  b485c630_f6a3_0d14_6f7c_47dd3f0e59c0["createSymbolProperty()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| b485c630_f6a3_0d14_6f7c_47dd3f0e59c0
  8861d5ff_1bb5_5f69_3181_a17fabca3cbd["createTagProperty()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| 8861d5ff_1bb5_5f69_3181_a17fabca3cbd
  ed1eb8e8_2e8d_edda_0c82_378ce6be376d["mapInstructionOperands()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| ed1eb8e8_2e8d_edda_0c82_378ce6be376d
  742aa636_b3b5_144a_8958_ab0283c6c7f6["handlePlace()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| 742aa636_b3b5_144a_8958_ab0283c6c7f6
  59a631ef_027f_ddb7_5458_3724685329fa["mapInstructionLValues()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| 59a631ef_027f_ddb7_5458_3724685329fa
  07a5e0fb_5991_44f9_c8c8_5058baf3f5af["handlelValue()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| 07a5e0fb_5991_44f9_c8c8_5058baf3f5af
  db56e09a_84ff_58ca_b65f_49565232080e["mapInstructionValueOperands()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| db56e09a_84ff_58ca_b65f_49565232080e
  7cb52864_400c_d704_d315_e21591a62514["mapTerminalOperands()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| 7cb52864_400c_d704_d315_e21591a62514
  68d905eb_a36a_0868_a230_3e11a3e4b577["handleIdentifier()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| 68d905eb_a36a_0868_a230_3e11a3e4b577
  ef8caafb_149f_27e1_3585_f21588c922cb["reversePostorderBlocks()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| ef8caafb_149f_27e1_3585_f21588c922cb
  7004a82b_d713_6fe8_d7e5_de3f61913067["markPredecessors()"]
  2a874f47_71f2_6231_f751_4f1e63d38258 -->|calls| 7004a82b_d713_6fe8_d7e5_de3f61913067
  style 2a874f47_71f2_6231_f751_4f1e63d38258 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Optimization/InlineJsxTransform.ts lines 66–428

export function inlineJsxTransform(
  fn: HIRFunction,
  inlineJsxTransformConfig: NonNullable<
    EnvironmentConfig['inlineJsxTransform']
  >,
): void {
  const inlinedJsxDeclarations: InlinedJsxDeclarationMap = new Map();
  /**
   * Step 1: Codegen the conditional and ReactElement object literal
   */
  for (const [_, currentBlock] of [...fn.body.blocks]) {
    let fallthroughBlockInstructions: Array<Instruction> | null = null;
    const instructionCount = currentBlock.instructions.length;
    for (let i = 0; i < instructionCount; i++) {
      const instr = currentBlock.instructions[i]!;
      // TODO: Support value blocks
      if (currentBlock.kind === 'value') {
        fn.env.logger?.logEvent(fn.env.filename, {
          kind: 'CompileDiagnostic',
          fnLoc: null,
          detail: {
            category: ErrorCategory.Todo,
            reason: 'JSX Inlining is not supported on value blocks',
            loc: instr.loc,
          },
        });
        continue;
      }
      switch (instr.value.kind) {
        case 'JsxExpression':
        case 'JsxFragment': {
          /**
           * Split into blocks for new IfTerminal:
           *   current, then, else, fallthrough
           */
          const currentBlockInstructions = currentBlock.instructions.slice(
            0,
            i,
          );
          const thenBlockInstructions = currentBlock.instructions.slice(
            i,
            i + 1,
          );
          const elseBlockInstructions: Array<Instruction> = [];
          fallthroughBlockInstructions ??= currentBlock.instructions.slice(
            i + 1,
          );

          const fallthroughBlockId = fn.env.nextBlockId;
          const fallthroughBlock: BasicBlock = {
            kind: currentBlock.kind,
            id: fallthroughBlockId,
            instructions: fallthroughBlockInstructions,
            terminal: currentBlock.terminal,
            preds: new Set(),
            phis: new Set(),
          };

          /**
           * Complete current block
           * - Add instruction for variable declaration
           * - Add instruction for LoadGlobal used by conditional
           * - End block with a new IfTerminal
           */
          const varPlace = createTemporaryPlace(fn.env, instr.value.loc);
          promoteTemporary(varPlace.identifier);
          const varLValuePlace = createTemporaryPlace(fn.env, instr.value.loc);
          const thenVarPlace = {
            ...varPlace,
            identifier: forkTemporaryIdentifier(
              fn.env.nextIdentifierId,
              varPlace.identifier,
            ),
          };
          const elseVarPlace = {
            ...varPlace,
            identifier: forkTemporaryIdentifier(
              fn.env.nextIdentifierId,
              varPlace.identifier,
            ),
          };

Subdomains

Frequently Asked Questions

What does inlineJsxTransform() do?
inlineJsxTransform() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/InlineJsxTransform.ts.
Where is inlineJsxTransform() defined?
inlineJsxTransform() is defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/InlineJsxTransform.ts at line 66.
What does inlineJsxTransform() call?
inlineJsxTransform() calls 16 function(s): createPropsProperties, createSymbolProperty, createTagProperty, createTemporaryPlace, fixScopeAndIdentifierRanges, handleIdentifier, handlePlace, handlelValue, and 8 more.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free