MCPcopy Create free account
hub / github.com/ygs-code/vue / checkNode

Function checkNode

vue.js:15343–15376  ·  view source on GitHub ↗
(node, errors)

Source from the content-addressed store, hash-verified

15341
15342 //检测 模板指令 把字符串变成真正的js是否有报错
15343 function checkNode(node, errors) {
15344 //node
15345 // 元素element 1
15346 // 属性attr 2
15347 // 文本text 3
15348 if (node.type === 1) { //text 节点类型,相当于在dom点中的空白区域
15349 //attrsMap 节点记录属性的对象
15350 for (var name in node.attrsMap) {
15351 if (dirRE.test(name)) { // var dirRE = /^v-|^@|^:/; 判断属性开头是否为 v- @ : 等 //如果是vue 中的属性则抽离出来
15352 var value = node.attrsMap[name]; //获取属性名称
15353 if (value) {
15354 if (name === 'v-for') { //如果是v-for
15355 checkFor(node, ("v-for=\"" + value + "\""), errors); //检查字符串模板 转换成js是否有报错
15356 } else if (onRE.test(name)) { // var onRE = /^@|^v-on:/; 匹配@开头 或者是v-on: 开头
15357 //检查事件是否含有关键词 type void delete 并且不是$开头的 收集错误信息
15358 checkEvent(value, (name + "=\"" + value + "\""), errors);
15359 } else {
15360 //检查字符串转成真正js的时候是否会报错 可以替代eval()
15361 checkExpression(value, (name + "=\"" + value + "\""), errors);
15362 }
15363 }
15364 }
15365 }
15366 if (node.children) { //如果有子节点则递归
15367 for (var i = 0; i < node.children.length; i++) {
15368 //递归子节点 检查子节点
15369 checkNode(node.children[i], errors);
15370 }
15371 }
15372 } else if (node.type === 2) {
15373 //检查属性 字符串转成真正js的时候是否会报错 可以替代eval()
15374 checkExpression(node.expression, node.text, errors);
15375 }
15376 }
15377
15378 //检查事件,去除掉模板字符串,匹配是否含有delete (任何字符) 或 typeof (任何字符) 或 void (任何字符) 关键词,检查字符串开头是否含有$
15379 function checkEvent(exp, text, errors) {

Callers 1

detectErrorsFunction · 0.85

Calls 3

checkForFunction · 0.85
checkEventFunction · 0.85
checkExpressionFunction · 0.85

Tested by

no test coverage detected