Home / Function/ overwriteAttrValue() — vite Function Reference

overwriteAttrValue() — vite Function Reference

Architecture documentation for the overwriteAttrValue() function in html.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  370852c5_4762_1633_45af_f5ae49f7fc4e["overwriteAttrValue()"]
  f8fe0737_718a_5509_b722_473f207d5906["html.ts"]
  370852c5_4762_1633_45af_f5ae49f7fc4e -->|defined in| f8fe0737_718a_5509_b722_473f207d5906
  39f26be8_b1d9_a756_3043_474687a6bbb7["buildHtmlPlugin()"]
  39f26be8_b1d9_a756_3043_474687a6bbb7 -->|calls| 370852c5_4762_1633_45af_f5ae49f7fc4e
  c7929a5b_9791_180a_9c0b_4f479fb4cf3f["devHtmlHook()"]
  c7929a5b_9791_180a_9c0b_4f479fb4cf3f -->|calls| 370852c5_4762_1633_45af_f5ae49f7fc4e
  style 370852c5_4762_1633_45af_f5ae49f7fc4e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/html.ts lines 257–281

export function overwriteAttrValue(
  s: MagicString,
  sourceCodeLocation: Token.Location,
  newValue: string,
): MagicString {
  const srcString = s.slice(
    sourceCodeLocation.startOffset,
    sourceCodeLocation.endOffset,
  )
  const valueStart = attrValueStartRE.exec(srcString)
  if (!valueStart) {
    // overwrite attr value can only be called for a well-defined value
    throw new Error(
      `[vite:html] internal error, failed to overwrite attribute value`,
    )
  }
  const wrapOffset = valueStart[1] === '"' || valueStart[1] === "'" ? 1 : 0
  const valueOffset = valueStart.index! + valueStart[0].length - 1
  s.update(
    sourceCodeLocation.startOffset + valueOffset + wrapOffset,
    sourceCodeLocation.endOffset - wrapOffset,
    newValue,
  )
  return s
}

Domain

Subdomains

Frequently Asked Questions

What does overwriteAttrValue() do?
overwriteAttrValue() is a function in the vite codebase, defined in packages/vite/src/node/plugins/html.ts.
Where is overwriteAttrValue() defined?
overwriteAttrValue() is defined in packages/vite/src/node/plugins/html.ts at line 257.
What calls overwriteAttrValue()?
overwriteAttrValue() is called by 2 function(s): buildHtmlPlugin, devHtmlHook.

Analyze Your Own Codebase

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

Try Supermodel Free