Home / Function/ prefixIdentifiers() — vue Function Reference

prefixIdentifiers() — vue Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  da297c1b_76f1_4af5_5266_fee8757f87ed["prefixIdentifiers()"]
  b313ae70_92bd_5f56_d45c_cb9fbd6806c9["actuallyCompile()"]
  b313ae70_92bd_5f56_d45c_cb9fbd6806c9 -->|calls| da297c1b_76f1_4af5_5266_fee8757f87ed
  31882be9_2c41_9ebd_3833_95fb4363ddb5["genCssVarsCode()"]
  31882be9_2c41_9ebd_3833_95fb4363ddb5 -->|calls| da297c1b_76f1_4af5_5266_fee8757f87ed
  eb301be5_f530_960e_129f_798877ea7f83["walkIdentifiers()"]
  da297c1b_76f1_4af5_5266_fee8757f87ed -->|calls| eb301be5_f530_960e_129f_798877ea7f83
  fc13b6b0_5b9d_e7ad_979a_66820fa0a811["isStaticProperty()"]
  da297c1b_76f1_4af5_5266_fee8757f87ed -->|calls| fc13b6b0_5b9d_e7ad_979a_66820fa0a811
  47c14f28_c1ca_52d4_cc59_404156ff9d1e["remove()"]
  da297c1b_76f1_4af5_5266_fee8757f87ed -->|calls| 47c14f28_c1ca_52d4_cc59_404156ff9d1e
  c7fb0b96_a593_dfb8_3f7a_2f40701511a4["toString()"]
  da297c1b_76f1_4af5_5266_fee8757f87ed -->|calls| c7fb0b96_a593_dfb8_3f7a_2f40701511a4
  style da297c1b_76f1_4af5_5266_fee8757f87ed fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/compiler-sfc/src/prefixIdentifiers.ts lines 19–82

export function prefixIdentifiers(
  source: string,
  isFunctional = false,
  isTS = false,
  babelOptions: ParserOptions = {},
  bindings?: BindingMetadata
) {
  const s = new MagicString(source)

  const plugins: ParserPlugin[] = [
    ...(isTS ? (['typescript'] as const) : []),
    ...(babelOptions?.plugins || [])
  ]

  const ast = parseExpression(source, {
    ...babelOptions,
    plugins
  })

  const isScriptSetup = bindings && bindings.__isScriptSetup !== false

  walkIdentifiers(
    ast,
    (ident, parent) => {
      const { name } = ident
      if (doNotPrefix(name)) {
        return
      }

      let prefix = `_vm.`
      if (isScriptSetup) {
        const type = bindings[name]
        if (type && type.startsWith('setup')) {
          prefix = `_setup.`
        }
      }

      if (isStaticProperty(parent) && parent.shorthand) {
        // property shorthand like { foo }, we need to add the key since
        // we rewrite the value
        // { foo } -> { foo: _vm.foo }
        s.appendLeft(ident.end!, `: ${prefix}${name}`)
      } else {
        s.prependRight(ident.start!, prefix)
      }
    },
    node => {
      if (node.type === 'WithStatement') {
        s.remove(node.start!, node.body.start! + 1)
        s.remove(node.end! - 1, node.end!)
        if (!isFunctional) {
          s.prependRight(
            node.start!,
            `var _vm=this,_c=_vm._self._c${
              isScriptSetup ? `,_setup=_vm._self._setupProxy;` : `;`
            }`
          )
        }
      }
    }
  )

  return s.toString()
}

Domain

Subdomains

Frequently Asked Questions

What does prefixIdentifiers() do?
prefixIdentifiers() is a function in the vue codebase.
What does prefixIdentifiers() call?
prefixIdentifiers() calls 4 function(s): isStaticProperty, remove, toString, walkIdentifiers.
What calls prefixIdentifiers()?
prefixIdentifiers() is called by 2 function(s): actuallyCompile, genCssVarsCode.

Analyze Your Own Codebase

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

Try Supermodel Free