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

Function transformModel

packages/compiler-dom/src/transforms/vModel.ts:20–127  ·  view source on GitHub ↗
(dir, node, context)

Source from the content-addressed store, hash-verified

18} from '../runtimeHelpers'
19
20export const transformModel: DirectiveTransform = (dir, node, context) => {
21 const baseResult = baseTransform(dir, node, context)
22 // base transform has errors OR component v-model (only need props)
23 if (!baseResult.props.length || node.tagType === ElementTypes.COMPONENT) {
24 return baseResult
25 }
26
27 if (dir.arg) {
28 context.onError(
29 createDOMCompilerError(
30 DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT,
31 dir.arg.loc,
32 ),
33 )
34 }
35
36 function checkDuplicatedValue() {
37 const value = findDir(node, 'bind')
38 if (value && isStaticArgOf(value.arg, 'value')) {
39 context.onError(
40 createDOMCompilerError(
41 DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE,
42 value.loc,
43 ),
44 )
45 }
46 }
47
48 const { tag } = node
49 const isCustomElement = context.isCustomElement(tag)
50 if (
51 tag === 'input' ||
52 tag === 'textarea' ||
53 tag === 'select' ||
54 isCustomElement
55 ) {
56 let directiveToUse = V_MODEL_TEXT
57 let isInvalidType = false
58 if (tag === 'input' || isCustomElement) {
59 const type = findProp(node, `type`)
60 if (type) {
61 if (type.type === NodeTypes.DIRECTIVE) {
62 // :type="foo"
63 directiveToUse = V_MODEL_DYNAMIC
64 } else if (type.value) {
65 switch (type.value.content) {
66 case 'radio':
67 directiveToUse = V_MODEL_RADIO
68 break
69 case 'checkbox':
70 directiveToUse = V_MODEL_CHECKBOX
71 break
72 case 'file':
73 isInvalidType = true
74 context.onError(
75 createDOMCompilerError(
76 DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT,
77 dir.loc,

Callers 1

ssrTransformModelFunction · 0.90

Calls 6

createDOMCompilerErrorFunction · 0.90
findPropFunction · 0.90
hasDynamicKeyVBindFunction · 0.90
checkDuplicatedValueFunction · 0.70
helperMethod · 0.65
filterMethod · 0.65

Tested by

no test coverage detected