Home / File/ resolve-slots.ts — vue Source File

resolve-slots.ts — vue Source File

Architecture documentation for resolve-slots.ts, a typescript file in the vue codebase. 2 imports, 3 dependents.

File typescript CoreRuntime Instance 2 imports 3 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  f7e6d498_cf3b_d729_68d1_b772bf90e35f["resolve-slots.ts"]
  f6868225_acf7_afdc_ebd3_15704ddb6566["vnode"]
  f7e6d498_cf3b_d729_68d1_b772bf90e35f --> f6868225_acf7_afdc_ebd3_15704ddb6566
  907f4994_ea28_43b1_7976_0db9f0e97637["component"]
  f7e6d498_cf3b_d729_68d1_b772bf90e35f --> 907f4994_ea28_43b1_7976_0db9f0e97637
  f3560440_54c1_5663_36f8_c7de54d7310b["lifecycle.ts"]
  f3560440_54c1_5663_36f8_c7de54d7310b --> f7e6d498_cf3b_d729_68d1_b772bf90e35f
  a8c0285c_59b2_d81b_1af0_c0cd9c2afe2d["render.ts"]
  a8c0285c_59b2_d81b_1af0_c0cd9c2afe2d --> f7e6d498_cf3b_d729_68d1_b772bf90e35f
  dfa00dc1_b5e1_fc4b_364c_221e22660e03["create-functional-component.ts"]
  dfa00dc1_b5e1_fc4b_364c_221e22660e03 --> f7e6d498_cf3b_d729_68d1_b772bf90e35f
  style f7e6d498_cf3b_d729_68d1_b772bf90e35f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type VNode from 'core/vdom/vnode'
import type { Component } from 'types/component'

/**
 * Runtime helper for resolving raw children VNodes into a slot object.
 */
export function resolveSlots(
  children: Array<VNode> | null | undefined,
  context: Component | null
): { [key: string]: Array<VNode> } {
  if (!children || !children.length) {
    return {}
  }
  const slots: Record<string, any> = {}
  for (let i = 0, l = children.length; i < l; i++) {
    const child = children[i]
    const data = child.data
    // remove slot attribute if the node is resolved as a Vue slot node
    if (data && data.attrs && data.attrs.slot) {
      delete data.attrs.slot
    }
    // named slots should only be respected if the vnode was rendered in the
    // same context.
    if (
      (child.context === context || child.fnContext === context) &&
      data &&
      data.slot != null
    ) {
      const name = data.slot
      const slot = slots[name] || (slots[name] = [])
      if (child.tag === 'template') {
        slot.push.apply(slot, child.children || [])
      } else {
        slot.push(child)
      }
    } else {
      ;(slots.default || (slots.default = [])).push(child)
    }
  }
  // ignore slots that contains only whitespace
  for (const name in slots) {
    if (slots[name].every(isWhitespace)) {
      delete slots[name]
    }
  }
  return slots
}

function isWhitespace(node: VNode): boolean {
  return (node.isComment && !node.asyncFactory) || node.text === ' '
}

Domain

Subdomains

Dependencies

  • component
  • vnode

Frequently Asked Questions

What does resolve-slots.ts do?
resolve-slots.ts is a source file in the vue codebase, written in typescript. It belongs to the CoreRuntime domain, Instance subdomain.
What functions are defined in resolve-slots.ts?
resolve-slots.ts defines 2 function(s): isWhitespace, resolveSlots.
What does resolve-slots.ts depend on?
resolve-slots.ts imports 2 module(s): component, vnode.
What files import resolve-slots.ts?
resolve-slots.ts is imported by 3 file(s): create-functional-component.ts, lifecycle.ts, render.ts.
Where is resolve-slots.ts in the architecture?
resolve-slots.ts is located at src/core/instance/render-helpers/resolve-slots.ts (domain: CoreRuntime, subdomain: Instance, directory: src/core/instance/render-helpers).

Analyze Your Own Codebase

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

Try Supermodel Free