Quellcode durchsuchen

[Feat 0000]代码优化

bobo04052021@163.com vor 9 Stunden
Ursprung
Commit
04f2cb8db9
1 geänderte Dateien mit 0 neuen und 73 gelöschten Zeilen
  1. 0 73
      .dsh-check/scan-that.mjs

+ 0 - 73
.dsh-check/scan-that.mjs

@@ -1,73 +0,0 @@
-import fs from "node:fs";
-
-const file = process.argv[2];
-const src = fs.readFileSync(file, "utf8");
-const start = src.indexOf("<script>") + "<script>".length;
-const end = src.indexOf("</script>", start);
-let body = src.slice(start, end);
-
-// 定位 methods 块
-const methodsAt = body.indexOf("methods: {");
-if (methodsAt < 0) {
-  console.log("未找到 methods 块");
-  process.exit(0);
-}
-
-let i = body.indexOf("{", methodsAt);
-let depth = 0;
-const methodsBodyStart = i + 1;
-let methodsBodyEnd = -1;
-for (; i < body.length; i += 1) {
-  const ch = body[i];
-  if (ch === "{") depth += 1;
-  else if (ch === "}") {
-    depth -= 1;
-    if (depth === 0) {
-      methodsBodyEnd = i;
-      break;
-    }
-  }
-}
-body = body.slice(methodsBodyStart, methodsBodyEnd);
-
-// 逐个方法(methods 内第一层)
-const methods = [];
-let k = 0;
-while (k < body.length) {
-  // 跳过分隔与注释
-  const rest = body.slice(k);
-  const header = /^\s*(?:[A-Za-z_$][\w$]*\s*\([^)]*\)\s*\{|async\s+[A-Za-z_$][\w$]*\s*\([^)]*\)\s*\{)/.exec(rest);
-  if (!header) {
-    k += 1;
-    continue;
-  }
-  const nameMatch = /([A-Za-z_$][\w$]*)\s*\(/.exec(header[0]);
-  const name = nameMatch ? nameMatch[1] : "(anon)";
-  const bodyStart = k + header[0].length;
-  let d = 1;
-  let j = bodyStart;
-  for (; j < body.length; j += 1) {
-    if (body[j] === "{") d += 1;
-    else if (body[j] === "}") {
-      d -= 1;
-      if (d === 0) break;
-    }
-  }
-  methods.push({ name, text: body.slice(bodyStart, j) });
-  k = j + 1;
-}
-
-const bad = [];
-methods.forEach(({ name, text }) => {
-  const usesThat = /(^|[^.\w$])that\s*\./.test(text);
-  const declaresThat = /(?:const|let|var)\s+that\s*=/.test(text);
-  if (usesThat && !declaresThat) bad.push(name);
-});
-
-console.log(`共扫描 ${methods.length} 个方法`);
-if (bad.length === 0) {
-  console.log("没有「用了 that 但未定义」的方法");
-} else {
-  console.log(`有问题的方法(${bad.length}): ${bad.join(", ")}`);
-  process.exitCode = 1;
-}