Home / Function/ walkDeclaration() — vue Function Reference

walkDeclaration() — vue Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  9f33888e_51b6_3ae6_bdc0_4f298af474a1["walkDeclaration()"]
  2c128e14_b26b_7375_e6ac_a951e5570a21["compileScript.ts"]
  9f33888e_51b6_3ae6_bdc0_4f298af474a1 -->|defined in| 2c128e14_b26b_7375_e6ac_a951e5570a21
  d277bc84_23de_2d80_b4cb_381ec6d7180b["compileScript()"]
  d277bc84_23de_2d80_b4cb_381ec6d7180b -->|calls| 9f33888e_51b6_3ae6_bdc0_4f298af474a1
  b4cd592b_5840_2d9a_e94e_742af06c0fa4["isCallOf()"]
  9f33888e_51b6_3ae6_bdc0_4f298af474a1 -->|calls| b4cd592b_5840_2d9a_e94e_742af06c0fa4
  55df138a_f56a_c064_8aae_fc9ff0885742["canNeverBeRef()"]
  9f33888e_51b6_3ae6_bdc0_4f298af474a1 -->|calls| 55df138a_f56a_c064_8aae_fc9ff0885742
  8587c8bb_b067_3227_7421_88d4b33b3f43["registerBinding()"]
  9f33888e_51b6_3ae6_bdc0_4f298af474a1 -->|calls| 8587c8bb_b067_3227_7421_88d4b33b3f43
  917b6a07_88bd_6ed5_4567_eefcf933dbc4["walkObjectPattern()"]
  9f33888e_51b6_3ae6_bdc0_4f298af474a1 -->|calls| 917b6a07_88bd_6ed5_4567_eefcf933dbc4
  80334005_c2f8_ab41_6a0c_f7ab6ffe79b0["walkArrayPattern()"]
  9f33888e_51b6_3ae6_bdc0_4f298af474a1 -->|calls| 80334005_c2f8_ab41_6a0c_f7ab6ffe79b0
  style 9f33888e_51b6_3ae6_bdc0_4f298af474a1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/compiler-sfc/src/compileScript.ts lines 1283–1347

function walkDeclaration(
  node: Declaration,
  bindings: Record<string, BindingTypes>,
  userImportAlias: Record<string, string>
) {
  if (node.type === 'VariableDeclaration') {
    const isConst = node.kind === 'const'
    // export const foo = ...
    for (const { id, init } of node.declarations) {
      const isDefineCall = !!(
        isConst &&
        isCallOf(
          init,
          c => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS
        )
      )
      if (id.type === 'Identifier') {
        let bindingType
        const userReactiveBinding = userImportAlias['reactive'] || 'reactive'
        if (isCallOf(init, userReactiveBinding)) {
          // treat reactive() calls as let since it's meant to be mutable
          bindingType = isConst
            ? BindingTypes.SETUP_REACTIVE_CONST
            : BindingTypes.SETUP_LET
        } else if (
          // if a declaration is a const literal, we can mark it so that
          // the generated render fn code doesn't need to unref() it
          isDefineCall ||
          (isConst && canNeverBeRef(init!, userReactiveBinding))
        ) {
          bindingType = isCallOf(init, DEFINE_PROPS)
            ? BindingTypes.SETUP_REACTIVE_CONST
            : BindingTypes.SETUP_CONST
        } else if (isConst) {
          if (isCallOf(init, userImportAlias['ref'] || 'ref')) {
            bindingType = BindingTypes.SETUP_REF
          } else {
            bindingType = BindingTypes.SETUP_MAYBE_REF
          }
        } else {
          bindingType = BindingTypes.SETUP_LET
        }
        registerBinding(bindings, id, bindingType)
      } else {
        if (isCallOf(init, DEFINE_PROPS)) {
          // skip walking props destructure
          return
        }
        if (id.type === 'ObjectPattern') {
          walkObjectPattern(id, bindings, isConst, isDefineCall)
        } else if (id.type === 'ArrayPattern') {
          walkArrayPattern(id, bindings, isConst, isDefineCall)
        }
      }
    }
  } else if (
    node.type === 'TSEnumDeclaration' ||
    node.type === 'FunctionDeclaration' ||
    node.type === 'ClassDeclaration'
  ) {
    // export function foo() {} / export class Foo {}
    // export declarations must be named.
    bindings[node.id!.name] = BindingTypes.SETUP_CONST
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does walkDeclaration() do?
walkDeclaration() is a function in the vue codebase, defined in packages/compiler-sfc/src/compileScript.ts.
Where is walkDeclaration() defined?
walkDeclaration() is defined in packages/compiler-sfc/src/compileScript.ts at line 1283.
What does walkDeclaration() call?
walkDeclaration() calls 5 function(s): canNeverBeRef, isCallOf, registerBinding, walkArrayPattern, walkObjectPattern.
What calls walkDeclaration()?
walkDeclaration() is called by 1 function(s): compileScript.

Analyze Your Own Codebase

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

Try Supermodel Free