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

Function ssrTransformModel

packages/compiler-ssr/src/transforms/ssrVModel.ts:27–191  ·  view source on GitHub ↗
(dir, node, context)

Source from the content-addressed store, hash-verified

25import type { DirectiveTransformResult } from 'packages/compiler-core/src/transform'
26
27export const ssrTransformModel: DirectiveTransform = (dir, node, context) => {
28 const model = dir.exp!
29
30 function checkDuplicatedValue() {
31 const value = findProp(node, 'value')
32 if (value) {
33 context.onError(
34 createDOMCompilerError(
35 DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE,
36 value.loc,
37 ),
38 )
39 }
40 }
41
42 const processSelectChildren = (children: TemplateChildNode[]) => {
43 children.forEach(child => {
44 if (child.type === NodeTypes.ELEMENT) {
45 processOption(child as PlainElementNode)
46 } else if (child.type === NodeTypes.FOR) {
47 processSelectChildren(child.children)
48 } else if (child.type === NodeTypes.IF) {
49 child.branches.forEach(b => processSelectChildren(b.children))
50 }
51 })
52 }
53
54 function processOption(plainNode: PlainElementNode) {
55 if (plainNode.tag === 'option') {
56 if (plainNode.props.findIndex(p => p.name === 'selected') === -1) {
57 const value = findValueBinding(plainNode)
58 plainNode.ssrCodegenNode!.elements.push(
59 createConditionalExpression(
60 createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [
61 createConditionalExpression(
62 createCallExpression(`Array.isArray`, [model]),
63 createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
64 model,
65 value,
66 ]),
67 createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
68 model,
69 value,
70 ]),
71 ),
72 ]),
73 createSimpleExpression(' selected', true),
74 createSimpleExpression('', true),
75 false /* no newline */,
76 ),
77 )
78 }
79 } else if (plainNode.tag === 'optgroup') {
80 processSelectChildren(plainNode.children)
81 }
82 }
83
84 if (node.tagType === ElementTypes.ELEMENT) {

Callers

nothing calls this directly

Calls 12

createDOMCompilerErrorFunction · 0.90
transformModelFunction · 0.90
createObjectPropertyFunction · 0.85
findPropFunction · 0.85
findValueBindingFunction · 0.85
createCallExpressionFunction · 0.85
hasDynamicKeyVBindFunction · 0.85
createInterpolationFunction · 0.85
processSelectChildrenFunction · 0.85
checkDuplicatedValueFunction · 0.70
helperMethod · 0.65

Tested by

no test coverage detected