(node, context)
| 10 | import { DOMErrorCodes, createDOMCompilerError } from '../errors' |
| 11 | |
| 12 | export 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 | |
| 59 | function hasMultipleChildren(node: ComponentNode | IfBranchNode): boolean { |
| 60 | // filter out potential comment nodes (#1352) and whitespace (#4637) |
nothing calls this directly
no test coverage detected