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
  4816b617_49b6_86ec_ba60_1b6ac824a31a["walkDeclaration()"]
  af57cd20_c4ce_0877_c02c_52056ca04d4a["compileScript()"]
  af57cd20_c4ce_0877_c02c_52056ca04d4a -->|calls| 4816b617_49b6_86ec_ba60_1b6ac824a31a
  65dd2fc2_3f14_bf7a_311d_99f9d039a8a7["isCallOf()"]
  4816b617_49b6_86ec_ba60_1b6ac824a31a -->|calls| 65dd2fc2_3f14_bf7a_311d_99f9d039a8a7
  88e9f5e4_bd74_6987_a9a2_2217c1e15c8d["canNeverBeRef()"]
  4816b617_49b6_86ec_ba60_1b6ac824a31a -->|calls| 88e9f5e4_bd74_6987_a9a2_2217c1e15c8d
  72b07125_46f6_2586_ee42_1bdaa78eb7e2["registerBinding()"]
  4816b617_49b6_86ec_ba60_1b6ac824a31a -->|calls| 72b07125_46f6_2586_ee42_1bdaa78eb7e2
  9ae6652a_4e20_d88f_ad15_1cfe7add8cc2["walkObjectPattern()"]
  4816b617_49b6_86ec_ba60_1b6ac824a31a -->|calls| 9ae6652a_4e20_d88f_ad15_1cfe7add8cc2
  8745b835_f44b_f5b6_ddbf_501938820c46["walkArrayPattern()"]
  4816b617_49b6_86ec_ba60_1b6ac824a31a -->|calls| 8745b835_f44b_f5b6_ddbf_501938820c46
  style 4816b617_49b6_86ec_ba60_1b6ac824a31a 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.
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