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

Function transformTransition

packages/compiler-dom/src/transforms/Transition.ts:12–57  ·  view source on GitHub ↗
(node, context)

Source from the content-addressed store, hash-verified

10import { DOMErrorCodes, createDOMCompilerError } from '../errors'
11
12export const transformTransition: NodeTransform = (node, context) => {
13 if (
14 node.type === NodeTypes.ELEMENT &&
15 node.tagType === ElementTypes.COMPONENT
16 ) {
17 const component = context.isBuiltInComponent(node.tag)
18 if (component === TRANSITION) {
19 return () => {
20 if (!node.children.length) {
21 return
22 }
23
24 // warn multiple transition children
25 if (hasMultipleChildren(node)) {
26 context.onError(
27 createDOMCompilerError(
28 DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN,
29 {
30 start: node.children[0].loc.start,
31 end: node.children[node.children.length - 1].loc.end,
32 source: '',
33 },
34 ),
35 )
36 }
37
38 // check if it's a single child w/ v-show
39 // if yes, inject "persisted: true" to the transition props
40 const child = node.children[0]
41 if (child.type === NodeTypes.ELEMENT) {
42 for (const p of child.props) {
43 if (p.type === NodeTypes.DIRECTIVE && p.name === 'show') {
44 node.props.push({
45 type: NodeTypes.ATTRIBUTE,
46 name: 'persisted',
47 nameLoc: node.loc,
48 value: undefined,
49 loc: node.loc,
50 })
51 }
52 }
53 }
54 }
55 }
56 }
57}
58
59function hasMultipleChildren(node: ComponentNode | IfBranchNode): boolean {
60 // filter out potential comment nodes (#1352) and whitespace (#4637)

Callers

nothing calls this directly

Calls 3

createDOMCompilerErrorFunction · 0.90
hasMultipleChildrenFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected