(exp, text, errors)
| 15425 | |
| 15426 | // new function 用来检测js错误 可以替代eval() 字符转换js检查 字符串变量指向Function,防止有些前端编译工具报错 |
| 15427 | function checkExpression(exp, text, errors) { |
| 15428 | try { |
| 15429 | // new function 用来检测js错误 可以替代eval() 字符转换js检查 字符串变量指向Function,防止有些前端编译工具报错 |
| 15430 | new Function(("return " + exp)); |
| 15431 | } catch (e) { |
| 15432 | //把里面的字符串替换成空的 |
| 15433 | //然后在匹配 |
| 15434 | // 'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' + |
| 15435 | // 'super,throw,while,yield,delete,export,import,return,switch,default,' + |
| 15436 | // 'extends,finally,continue,debugger,function,arguments' 这些关键词 |
| 15437 | var keywordMatch = exp.replace(stripStringRE, '').match(prohibitedKeywordRE); |
| 15438 | |
| 15439 | if (keywordMatch) { //收集错误信息 |
| 15440 | errors.push( |
| 15441 | "avoid using JavaScript keyword as property name: " + |
| 15442 | "\"" + (keywordMatch[0]) + "\"\n Raw expression: " + (text.trim()) |
| 15443 | ); |
| 15444 | } else { |
| 15445 | errors.push( |
| 15446 | "invalid expression: " + (e.message) + " in\n\n" + |
| 15447 | " " + exp + "\n\n" + |
| 15448 | " Raw expression: " + (text.trim()) + "\n" |
| 15449 | ); |
| 15450 | } |
| 15451 | } |
| 15452 | } |
| 15453 | |
| 15454 | /* |
| 15455 | * |
no outgoing calls
no test coverage detected