Przeglądaj źródła

fix(scripts): verify-vue-compile 模板校验补上 tips 级致命告警

只检查 compiler.errors 会漏掉「属性被切断」这类问题——vue-template-compiler
把 "text ... outside root element will be ignored" 放在 res.tips 里,退出码
仍是 PASS,而 HBuilderX 打包会直接 Module Error 失败(本次 fontScale 接线脚本
插入 :style 切断 v-if="x.length > 0" 就是这样漏过去的)。

现在把以下 tips 一并判为失败:
- outside root element will be ignored(标签被截断/属性值被甩到标签外)
- duplicate attribute(脚本重复插入同名属性)
- exactly one root element(多根节点,小程序编译必失败)

自测:构造 v-if="alerts.length  :style=..."> 0" 的坏样本,
改造前 PASS(0),改造后退出码 1 并指出具体文件与原因。
liaoxg 3 tygodni temu
rodzic
commit
29003af7da
1 zmienionych plików z 8 dodań i 1 usunięć
  1. 8 1
      cfc-frontend/scripts/verify-vue-compile.js

+ 8 - 1
cfc-frontend/scripts/verify-vue-compile.js

@@ -71,7 +71,14 @@ for (const abs of files) {
     const tpl = sfc.template || ''
     if (tpl) {
       const res = compiler.compile(tpl)
-      if (res.errors && res.errors.length) fail(rel, 'template', res.errors.join(' | '))
+      // tips 里也有会打断编译的:属性被切断会报 "outside root element will be ignored"
+      // (如 v-if="x.length > 0" 被脚本插入 :style 后 `> 0"` 甩到标签外),
+      // 它不属于 errors,只看 errors 会漏判。
+      const badTips = (res.tips || []).filter(t =>
+        /outside root element|duplicate attribute|exactly one root element/i.test(String(t))
+      )
+      const problems = [].concat(res.errors || [], badTips)
+      if (problems.length) fail(rel, 'template', problems.join(' | '))
       else tplOk++
     } else tplOk++
   }