MCPcopy
hub / github.com/vuejs/core / trackSlotScopes

Function trackSlotScopes

packages/compiler-core/src/transforms/vSlot.ts:48–71  ·  view source on GitHub ↗
(node, context)

Source from the content-addressed store, hash-verified

46// Note the exit callback is executed before buildSlots() on the same node,
47// so only nested slots see positive numbers.
48export const trackSlotScopes: NodeTransform = (node, context) => {
49 if (
50 node.type === NodeTypes.ELEMENT &&
51 (node.tagType === ElementTypes.COMPONENT ||
52 node.tagType === ElementTypes.TEMPLATE)
53 ) {
54 // We are only checking non-empty v-slot here
55 // since we only care about slots that introduce scope variables.
56 const vSlot = findDir(node, 'slot')
57 if (vSlot) {
58 const slotProps = vSlot.exp
59 if (!__BROWSER__ && context.prefixIdentifiers) {
60 slotProps && context.addIdentifiers(slotProps)
61 }
62 context.scopes.vSlot++
63 return () => {
64 if (!__BROWSER__ && context.prefixIdentifiers) {
65 slotProps && context.removeIdentifiers(slotProps)
66 }
67 context.scopes.vSlot--
68 }
69 }
70 }
71}
72
73// A NodeTransform that tracks scope identifiers for scoped slots with v-for.
74// This transform is only applied in non-browser builds with { prefixIdentifiers: true }

Callers

nothing calls this directly

Calls 3

findDirFunction · 0.90
addIdentifiersMethod · 0.80
removeIdentifiersMethod · 0.80

Tested by

no test coverage detected