Home / Function/ extractImportedBindings() — vite Function Reference

extractImportedBindings() — vite Function Reference

Architecture documentation for the extractImportedBindings() function in importAnalysis.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  bcabd234_6f1d_eea3_3607_32b7847619a0["extractImportedBindings()"]
  5a7b98e4_4eb1_dfca_508b_2d43e2a077e6["importAnalysis.ts"]
  bcabd234_6f1d_eea3_3607_32b7847619a0 -->|defined in| 5a7b98e4_4eb1_dfca_508b_2d43e2a077e6
  a1fc1de5_905b_efe7_d960_3597604fbdfe["importAnalysisPlugin()"]
  a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| bcabd234_6f1d_eea3_3607_32b7847619a0
  style bcabd234_6f1d_eea3_3607_32b7847619a0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/importAnalysis.ts lines 146–193

function extractImportedBindings(
  id: string,
  source: string,
  importSpec: ImportSpecifier,
  importedBindings: Map<string, Set<string>>,
) {
  let bindings = importedBindings.get(id)
  if (!bindings) {
    bindings = new Set<string>()
    importedBindings.set(id, bindings)
  }

  const isDynamic = importSpec.d > -1
  const isMeta = importSpec.d === -2
  if (isDynamic || isMeta) {
    // this basically means the module will be impacted by any change in its dep
    bindings.add('*')
    return
  }

  const exp = source.slice(importSpec.ss, importSpec.se)
  ESM_STATIC_IMPORT_RE.lastIndex = 0
  const match = ESM_STATIC_IMPORT_RE.exec(exp)
  if (!match) {
    return
  }

  const staticImport: StaticImport = {
    type: 'static',
    code: match[0],
    start: match.index,
    end: match.index + match[0].length,
    imports: match.groups!.imports,
    specifier: match.groups!.specifier,
  }
  const parsed = parseStaticImport(staticImport)
  if (parsed.namespacedImport) {
    bindings.add('*')
  }
  if (parsed.defaultImport) {
    bindings.add('default')
  }
  if (parsed.namedImports) {
    for (const name of Object.keys(parsed.namedImports)) {
      bindings.add(name)
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does extractImportedBindings() do?
extractImportedBindings() is a function in the vite codebase, defined in packages/vite/src/node/plugins/importAnalysis.ts.
Where is extractImportedBindings() defined?
extractImportedBindings() is defined in packages/vite/src/node/plugins/importAnalysis.ts at line 146.
What calls extractImportedBindings()?
extractImportedBindings() is called by 1 function(s): importAnalysisPlugin.

Analyze Your Own Codebase

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

Try Supermodel Free