Home / Function/ codegenArrayPattern() — react Function Reference

codegenArrayPattern() — react Function Reference

Architecture documentation for the codegenArrayPattern() function in CodegenReactiveFunction.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  aae33d98_de86_6a92_adb8_6526404234ff["codegenArrayPattern()"]
  dc7f10c2_c914_a162_d02b_a10a15c64a5f["CodegenReactiveFunction.ts"]
  aae33d98_de86_6a92_adb8_6526404234ff -->|defined in| dc7f10c2_c914_a162_d02b_a10a15c64a5f
  fa00221c_3f87_f634_2655_5b0ca5860306["codegenLValue()"]
  fa00221c_3f87_f634_2655_5b0ca5860306 -->|calls| aae33d98_de86_6a92_adb8_6526404234ff
  073c81a5_c389_d108_5b8f_4d6dc6eece83["push()"]
  aae33d98_de86_6a92_adb8_6526404234ff -->|calls| 073c81a5_c389_d108_5b8f_4d6dc6eece83
  fa00221c_3f87_f634_2655_5b0ca5860306["codegenLValue()"]
  aae33d98_de86_6a92_adb8_6526404234ff -->|calls| fa00221c_3f87_f634_2655_5b0ca5860306
  style aae33d98_de86_6a92_adb8_6526404234ff fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts lines 2501–2538

function codegenArrayPattern(
  cx: Context,
  pattern: ArrayPattern,
): t.ArrayPattern {
  const hasHoles = !pattern.items.every(e => e.kind !== 'Hole');
  if (hasHoles) {
    const result = createArrayPattern(pattern.loc, []);
    /*
     * Older versions of babel have a validation bug fixed by
     * https://github.com/babel/babel/pull/10917
     * https://github.com/babel/babel/commit/e7b80a2cb93cf28010207fc3cdd19b4568ca35b9#diff-19b555d2f3904c206af406540d9df200b1e16befedb83ff39ebfcbd876f7fa8aL52
     *
     * Link to buggy older version (observe that elements must be PatternLikes here)
     * https://github.com/babel/babel/blob/v7.7.4/packages/babel-types/src/definitions/es2015.js#L50-L53
     *
     * Link to newer versions with correct validation (observe elements can be PatternLike | null)
     * https://github.com/babel/babel/blob/v7.23.0/packages/babel-types/src/definitions/core.ts#L1306-L1311
     */
    for (const item of pattern.items) {
      if (item.kind === 'Hole') {
        result.elements.push(null);
      } else {
        result.elements.push(codegenLValue(cx, item));
      }
    }
    return result;
  } else {
    return createArrayPattern(
      pattern.loc,
      pattern.items.map(item => {
        if (item.kind === 'Hole') {
          return null;
        }
        return codegenLValue(cx, item);
      }),
    );
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does codegenArrayPattern() do?
codegenArrayPattern() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts.
Where is codegenArrayPattern() defined?
codegenArrayPattern() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts at line 2501.
What does codegenArrayPattern() call?
codegenArrayPattern() calls 2 function(s): codegenLValue, push.
What calls codegenArrayPattern()?
codegenArrayPattern() is called by 1 function(s): codegenLValue.

Analyze Your Own Codebase

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

Try Supermodel Free