Home / Function/ printCodeFrame() — react Function Reference

printCodeFrame() — react Function Reference

Architecture documentation for the printCodeFrame() function in CompilerError.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  c4a899b9_3ed3_b9e8_fdb0_decfd5276099["printCodeFrame()"]
  e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"]
  c4a899b9_3ed3_b9e8_fdb0_decfd5276099 -->|defined in| e96f281e_f381_272d_2359_3e6a091c9a1d
  e39dece3_8891_8533_6625_5397539eb098["printErrorMessage()"]
  e39dece3_8891_8533_6625_5397539eb098 -->|calls| c4a899b9_3ed3_b9e8_fdb0_decfd5276099
  87c7e084_efd0_e72a_89ba_0eea447fbc45["printErrorMessage()"]
  87c7e084_efd0_e72a_89ba_0eea447fbc45 -->|calls| c4a899b9_3ed3_b9e8_fdb0_decfd5276099
  style c4a899b9_3ed3_b9e8_fdb0_decfd5276099 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts lines 525–563

function printCodeFrame(
  source: string,
  loc: t.SourceLocation,
  message: string,
): string {
  const printed = codeFrameColumns(
    source,
    {
      start: {
        line: loc.start.line,
        column: loc.start.column + 1,
      },
      end: {
        line: loc.end.line,
        column: loc.end.column + 1,
      },
    },
    {
      message,
      linesAbove: CODEFRAME_LINES_ABOVE,
      linesBelow: CODEFRAME_LINES_BELOW,
    },
  );
  const lines = printed.split(/\r?\n/);
  if (loc.end.line - loc.start.line < CODEFRAME_MAX_LINES) {
    return printed;
  }
  const pipeIndex = lines[0].indexOf('|');
  return [
    ...lines.slice(
      0,
      CODEFRAME_LINES_ABOVE + CODEFRAME_ABBREVIATED_SOURCE_LINES,
    ),
    ' '.repeat(pipeIndex) + '…',
    ...lines.slice(
      -(CODEFRAME_LINES_BELOW + CODEFRAME_ABBREVIATED_SOURCE_LINES),
    ),
  ].join('\n');
}

Domain

Subdomains

Frequently Asked Questions

What does printCodeFrame() do?
printCodeFrame() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts.
Where is printCodeFrame() defined?
printCodeFrame() is defined in compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts at line 525.
What calls printCodeFrame()?
printCodeFrame() is called by 2 function(s): printErrorMessage, printErrorMessage.

Analyze Your Own Codebase

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

Try Supermodel Free