Home / File/ babelUtils.ts — vue Source File

babelUtils.ts — vue Source File

Architecture documentation for babelUtils.ts, a typescript file in the vue codebase. 2 imports, 2 dependents.

File typescript SfcCompiler ScriptCompiler 2 imports 2 dependents 11 functions

Entity Profile

Dependency Diagram

graph LR
  fcee39ec_18fe_7a99_fb49_d33db4d055a4["babelUtils.ts"]
  e2809cda_11dc_0cb5_cf65_8c95846af83b["types"]
  fcee39ec_18fe_7a99_fb49_d33db4d055a4 --> e2809cda_11dc_0cb5_cf65_8c95846af83b
  2c8d989d_159d_0388_046d_750ad8f009e0["estree-walker"]
  fcee39ec_18fe_7a99_fb49_d33db4d055a4 --> 2c8d989d_159d_0388_046d_750ad8f009e0
  c9346cac_54e3_f6ca_68a7_03c6e82c9609["compileScript.ts"]
  c9346cac_54e3_f6ca_68a7_03c6e82c9609 --> fcee39ec_18fe_7a99_fb49_d33db4d055a4
  472584c7_15d2_7ac4_2300_5c0fac3bab21["prefixIdentifiers.ts"]
  472584c7_15d2_7ac4_2300_5c0fac3bab21 --> fcee39ec_18fe_7a99_fb49_d33db4d055a4
  style fcee39ec_18fe_7a99_fb49_d33db4d055a4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// https://github.com/vuejs/core/blob/main/packages/compiler-core/src/babelUtils.ts

// should only use types from @babel/types
// do not import runtime methods
import type {
  Identifier,
  Node,
  Function,
  ObjectProperty,
  BlockStatement,
  Program
} from '@babel/types'
import { walk } from 'estree-walker'

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
// ... (364 more lines)

Domain

Subdomains

Dependencies

  • estree-walker
  • types

Frequently Asked Questions

What does babelUtils.ts do?
babelUtils.ts is a source file in the vue codebase, written in typescript. It belongs to the SfcCompiler domain, ScriptCompiler subdomain.
What functions are defined in babelUtils.ts?
babelUtils.ts defines 11 function(s): extractIdentifiers, isFunctionType, isInDestructureAssignment, isReferenced, isReferencedIdentifier, isStaticProperty, isStaticPropertyKey, markScopeIdentifier, walkBlockDeclarations, walkFunctionParams, and 1 more.
What does babelUtils.ts depend on?
babelUtils.ts imports 2 module(s): estree-walker, types.
What files import babelUtils.ts?
babelUtils.ts is imported by 2 file(s): compileScript.ts, prefixIdentifiers.ts.
Where is babelUtils.ts in the architecture?
babelUtils.ts is located at packages/compiler-sfc/src/babelUtils.ts (domain: SfcCompiler, subdomain: ScriptCompiler, directory: packages/compiler-sfc/src).

Analyze Your Own Codebase

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

Try Supermodel Free