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
  b5dd2b92_1eb8_9be8_c96d_7d157359d180["walkDeclaration()"]
  b9f12a63_b611_1b00_0717_3ff21d7ce156["compileScript.ts"]
  b5dd2b92_1eb8_9be8_c96d_7d157359d180 -->|defined in| b9f12a63_b611_1b00_0717_3ff21d7ce156
  6195696d_b4e9_b5d7_3dd5_1966a03d855f["compileScript()"]
  6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| b5dd2b92_1eb8_9be8_c96d_7d157359d180
  72aee498_7b56_2d69_75c1_073eba5bb101["isCallOf()"]
  b5dd2b92_1eb8_9be8_c96d_7d157359d180 -->|calls| 72aee498_7b56_2d69_75c1_073eba5bb101
  e9b7981d_dc91_839a_17f5_a4ecd20a5b0f["canNeverBeRef()"]
  b5dd2b92_1eb8_9be8_c96d_7d157359d180 -->|calls| e9b7981d_dc91_839a_17f5_a4ecd20a5b0f
  728798bd_d0a3_3f87_32eb_839c83a9e416["registerBinding()"]
  b5dd2b92_1eb8_9be8_c96d_7d157359d180 -->|calls| 728798bd_d0a3_3f87_32eb_839c83a9e416
  d6ab12f6_4277_5388_3a07_cb9ebe239e5f["walkObjectPattern()"]
  b5dd2b92_1eb8_9be8_c96d_7d157359d180 -->|calls| d6ab12f6_4277_5388_3a07_cb9ebe239e5f
  f1063681_e6da_d3c4_2c08_889e677edbc4["walkArrayPattern()"]
  b5dd2b92_1eb8_9be8_c96d_7d157359d180 -->|calls| f1063681_e6da_d3c4_2c08_889e677edbc4
  style b5dd2b92_1eb8_9be8_c96d_7d157359d180 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