Home / Function/ generateCodeFrame() — vue Function Reference

generateCodeFrame() — vue Function Reference

Architecture documentation for the generateCodeFrame() function in codeframe.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  31503a99_436d_a6aa_9429_398a818a20a1["generateCodeFrame()"]
  af57cd20_c4ce_0877_c02c_52056ca04d4a["compileScript()"]
  af57cd20_c4ce_0877_c02c_52056ca04d4a -->|calls| 31503a99_436d_a6aa_9429_398a818a20a1
  f2d18c28_9782_02d0_c983_083b86068c69["createCompileToFunctionFn()"]
  f2d18c28_9782_02d0_c983_083b86068c69 -->|calls| 31503a99_436d_a6aa_9429_398a818a20a1
  a16420b7_c37a_099c_fe39_3b9d6d20d228["repeat()"]
  31503a99_436d_a6aa_9429_398a818a20a1 -->|calls| a16420b7_c37a_099c_fe39_3b9d6d20d228
  style 31503a99_436d_a6aa_9429_398a818a20a1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/compiler/codeframe.ts lines 3–37

export function generateCodeFrame(
  source: string,
  start: number = 0,
  end: number = source.length
): string {
  const lines = source.split(/\r?\n/)
  let count = 0
  const res: string[] = []
  for (let i = 0; i < lines.length; i++) {
    count += lines[i].length + 1
    if (count >= start) {
      for (let j = i - range; j <= i + range || end > count; j++) {
        if (j < 0 || j >= lines.length) continue
        res.push(
          `${j + 1}${repeat(` `, 3 - String(j + 1).length)}|  ${lines[j]}`
        )
        const lineLength = lines[j].length
        if (j === i) {
          // push underline
          const pad = start - (count - lineLength) + 1
          const length = end > count ? lineLength - pad : end - start
          res.push(`   |  ` + repeat(` `, pad) + repeat(`^`, length))
        } else if (j > i) {
          if (end > count) {
            const length = Math.min(end - count, lineLength)
            res.push(`   |  ` + repeat(`^`, length))
          }
          count += lineLength + 1
        }
      }
      break
    }
  }
  return res.join('\n')
}

Subdomains

Calls

Frequently Asked Questions

What does generateCodeFrame() do?
generateCodeFrame() is a function in the vue codebase.
What does generateCodeFrame() call?
generateCodeFrame() calls 1 function(s): repeat.
What calls generateCodeFrame()?
generateCodeFrame() is called by 2 function(s): compileScript, createCompileToFunctionFn.

Analyze Your Own Codebase

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

Try Supermodel Free