MCPcopy
hub / github.com/ygs-code/vue / preTransformNode

Function preTransformNode

vue.js:14083–14173  ·  view source on GitHub ↗
(
        el,  //虚拟dom  vonde
        options
    )

Source from the content-addressed store, hash-verified

14081 // preTransformNode把attrsMap与attrsList属性值转换添加到el ast虚拟dom中为虚拟dom添加for,alias,iterator1,iterator2,
14082 // addRawAttr ,type ,key, ref,slotName或者slotScope或者slot,component或者inlineTemplate , plain,if ,else,elseif 属性
14083 function preTransformNode(
14084 el, //虚拟dom vonde
14085 options
14086 ) {
14087 if (el.tag === 'input') { //如果是input标签
14088
14089 var map = el.attrsMap; //获取vonde 所有属性
14090 if (!map['v-model']) { //如果属性中没有v-model 则不需要执行
14091 return
14092 }
14093
14094 var typeBinding; //类型
14095 if (map[':type'] || map['v-bind:type']) { //获取类型属性
14096 typeBinding = getBindingAttr(el, 'type'); //获取类型属性值
14097 }
14098 if (!map.type && !typeBinding && map['v-bind']) { //如果获取不到type属性也获取不到v-bind:type属性,可以获取到v-bind属性
14099 typeBinding = "(" + (map['v-bind']) + ").type"; //获取到v-bind的值,比如v-bind等于abc变成 (abc).type
14100 }
14101
14102 if (typeBinding) { //判断 typeBinding 是否存在
14103 var ifCondition = getAndRemoveAttr(el, 'v-if', true); //获取v-if值
14104 var ifConditionExtra = ifCondition ? ("&&(" + ifCondition + ")") : ""; //判断if是否有值比如v-if="flag" 如果有 变成 &&(flag)
14105 var hasElse = getAndRemoveAttr(el, 'v-else', true) != null; //获取 v-else 属性值 标志 如果有有 可能是 '' , ''!= null 为真
14106 var elseIfCondition = getAndRemoveAttr(el, 'v-else-if', true); //获取v-else-if 的值
14107 // 1. checkbox 克隆 创建 checkbox ast 元素
14108 var branch0 = cloneASTElement(el);
14109 // process for on the main node
14110 //判断获取v-for属性是否存在如果有则转义 v-for指令 把for,alias,iterator1,iterator2属性添加到虚拟dom中
14111 processFor(branch0);
14112
14113 //添加type 属性 值为checkbox
14114 addRawAttr(branch0, 'type', 'checkbox');
14115
14116 //校验属性的值,为el添加muted, events,nativeEvents,directives, key, ref,slotName或者slotScope或者slot,component或者inlineTemplate 标志 属性
14117 processElement(branch0, options);
14118
14119 branch0.processed = true; // prevent it from double-processed 防止它被重复处理
14120 branch0.if = "(" + typeBinding + ")==='checkbox'" + ifConditionExtra; // ifConditionExtra 是 判断if是否有值比如v-if="flag" 如果有 变成 &&(flag) 最终合并成 ((abc).type)===checkbox&&(flag)
14121 //为if指令添加标记
14122 addIfCondition(
14123 branch0, //虚拟dom
14124 {
14125 exp: branch0.if, //if指令的标志
14126 block: branch0 //虚拟dom
14127 }
14128 );
14129 // 2. add radio else-if condition 添加radio else-if条件
14130 //克隆 创建 radio ast 元素
14131 var branch1 = cloneASTElement(el);
14132
14133 //删除v-for 属性
14134 getAndRemoveAttr(branch1, 'v-for', true);
14135
14136 //添加type 属性
14137 addRawAttr(branch1, 'type', 'radio');
14138
14139 //校验属性的值,为el 虚拟dom添加muted, events,nativeEvents,directives, key, ref,slotName或者slotScope或者slot,component或者inlineTemplate 标志 属性
14140 processElement(branch1, options);

Callers

nothing calls this directly

Calls 7

getBindingAttrFunction · 0.85
getAndRemoveAttrFunction · 0.85
cloneASTElementFunction · 0.85
processForFunction · 0.85
addRawAttrFunction · 0.85
processElementFunction · 0.85
addIfConditionFunction · 0.85

Tested by

no test coverage detected