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
  fefea729_cf80_e4f2_675b_000b41fc85a5["prefixIdentifiers()"]
  799ac4a1_7d08_dd24_f075_2bfd21b8092b["prefixIdentifiers.ts"]
  fefea729_cf80_e4f2_675b_000b41fc85a5 -->|defined in| 799ac4a1_7d08_dd24_f075_2bfd21b8092b
  d0674cfc_3db7_1770_6611_e035dd09e78e["actuallyCompile()"]
  d0674cfc_3db7_1770_6611_e035dd09e78e -->|calls| fefea729_cf80_e4f2_675b_000b41fc85a5
  847be4cb_fc6a_9296_b72f_58b4cc679dd7["genCssVarsCode()"]
  847be4cb_fc6a_9296_b72f_58b4cc679dd7 -->|calls| fefea729_cf80_e4f2_675b_000b41fc85a5
  6821e51e_382f_8ff8_ca9d_3b77f896018a["walkIdentifiers()"]
  fefea729_cf80_e4f2_675b_000b41fc85a5 -->|calls| 6821e51e_382f_8ff8_ca9d_3b77f896018a
  16e9bc98_ed99_1008_693b_a5b55bf0225e["isStaticProperty()"]
  fefea729_cf80_e4f2_675b_000b41fc85a5 -->|calls| 16e9bc98_ed99_1008_693b_a5b55bf0225e
  style fefea729_cf80_e4f2_675b_000b41fc85a5 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, defined in packages/compiler-sfc/src/prefixIdentifiers.ts.
Where is prefixIdentifiers() defined?
prefixIdentifiers() is defined in packages/compiler-sfc/src/prefixIdentifiers.ts at line 19.
What does prefixIdentifiers() call?
prefixIdentifiers() calls 2 function(s): isStaticProperty, 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