Home / Function/ walkIdentifiers() — vue Function Reference

walkIdentifiers() — vue Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  89db3100_db23_2ba5_52ae_1299b220043a["walkIdentifiers()"]
  af57cd20_c4ce_0877_c02c_52056ca04d4a["compileScript()"]
  af57cd20_c4ce_0877_c02c_52056ca04d4a -->|calls| 89db3100_db23_2ba5_52ae_1299b220043a
  d1f8290b_acd6_6448_2aa7_1bc8ba241901["processExp()"]
  d1f8290b_acd6_6448_2aa7_1bc8ba241901 -->|calls| 89db3100_db23_2ba5_52ae_1299b220043a
  daf5feaa_5661_e63c_80fa_09f5265e529c["prefixIdentifiers()"]
  daf5feaa_5661_e63c_80fa_09f5265e529c -->|calls| 89db3100_db23_2ba5_52ae_1299b220043a
  fea06cdf_d012_3d40_57ee_6d26231cf910["isReferencedIdentifier()"]
  89db3100_db23_2ba5_52ae_1299b220043a -->|calls| fea06cdf_d012_3d40_57ee_6d26231cf910
  b79c9d98_93c8_a683_7e51_be115b63f8e5["isFunctionType()"]
  89db3100_db23_2ba5_52ae_1299b220043a -->|calls| b79c9d98_93c8_a683_7e51_be115b63f8e5
  c2fbcf91_894a_9687_06b1_c880f607d668["walkFunctionParams()"]
  89db3100_db23_2ba5_52ae_1299b220043a -->|calls| c2fbcf91_894a_9687_06b1_c880f607d668
  fb4ee6b7_365f_2a4c_8784_a7a6f85b364d["markScopeIdentifier()"]
  89db3100_db23_2ba5_52ae_1299b220043a -->|calls| fb4ee6b7_365f_2a4c_8784_a7a6f85b364d
  f404d19f_6b3c_ba8d_d39d_54669aacbf94["walkBlockDeclarations()"]
  89db3100_db23_2ba5_52ae_1299b220043a -->|calls| f404d19f_6b3c_ba8d_d39d_54669aacbf94
  style 89db3100_db23_2ba5_52ae_1299b220043a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/compiler-sfc/src/babelUtils.ts lines 15–85

export function walkIdentifiers(
  root: Node,
  onIdentifier: (
    node: Identifier,
    parent: Node,
    parentStack: Node[],
    isReference: boolean,
    isLocal: boolean
  ) => void,
  onNode?: (node: Node) => void
) {
  const includeAll = false
  const parentStack: Node[] = []
  const knownIds: Record<string, number> = Object.create(null)

  const rootExp =
    root.type === 'Program' &&
    root.body[0].type === 'ExpressionStatement' &&
    root.body[0].expression

  ;(walk as any)(root, {
    enter(node: Node & { scopeIds?: Set<string> }, parent: Node | undefined) {
      parent && parentStack.push(parent)
      if (
        parent &&
        parent.type.startsWith('TS') &&
        parent.type !== 'TSAsExpression' &&
        parent.type !== 'TSNonNullExpression' &&
        parent.type !== 'TSTypeAssertion'
      ) {
        return this.skip()
      }

      if (onNode) onNode(node)

      if (node.type === 'Identifier') {
        const isLocal = !!knownIds[node.name]
        const isRefed = isReferencedIdentifier(node, parent!, parentStack)
        if (includeAll || (isRefed && !isLocal)) {
          onIdentifier(node, parent!, parentStack, isRefed, isLocal)
        }
      } else if (
        node.type === 'ObjectProperty' &&
        parent!.type === 'ObjectPattern'
      ) {
        // mark property in destructure pattern
        ;(node as any).inPattern = true
      } else if (isFunctionType(node)) {
        // walk function expressions and add its arguments to known identifiers
        // so that we don't prefix them
        walkFunctionParams(node, id => markScopeIdentifier(node, id, knownIds))
      } else if (node.type === 'BlockStatement') {
        // #3445 record block-level local variables
        walkBlockDeclarations(node, id =>
          markScopeIdentifier(node, id, knownIds)
        )
      }
    },
    leave(node: Node & { scopeIds?: Set<string> }, parent: Node | undefined) {
      parent && parentStack.pop()
      if (node !== rootExp && node.scopeIds) {
        for (const id of node.scopeIds) {
          knownIds[id]--
          if (knownIds[id] === 0) {
            delete knownIds[id]
          }
        }
      }
    }
  })
}

Domain

Subdomains

Frequently Asked Questions

What does walkIdentifiers() do?
walkIdentifiers() is a function in the vue codebase.
What does walkIdentifiers() call?
walkIdentifiers() calls 5 function(s): isFunctionType, isReferencedIdentifier, markScopeIdentifier, walkBlockDeclarations, walkFunctionParams.
What calls walkIdentifiers()?
walkIdentifiers() is called by 3 function(s): compileScript, prefixIdentifiers, processExp.

Analyze Your Own Codebase

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

Try Supermodel Free