You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.5 KiB

5 hours ago
# -*- coding: utf-8 -*-
"""统一 demo 静态校验:重复 const / onclick 函数覆盖 / 重复 function 定义。"""
import io, re, subprocess, sys, collections
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
P = r'E:\code\crm-backend-matt\.scratch\a7-acceptance\demo\index.html'
t = open(P, encoding='utf-8').read()
js = re.search(r'<script>(.*)</script>', t, re.S).group(1)
# 1. node --check 语法校验
r = subprocess.run(['node', '--check', '--input-type=commonjs', '-'], input=js.encode('utf-8'),
capture_output=True)
print('node --check:', 'OK' if r.returncode == 0 else 'FAIL')
if r.returncode != 0:
print(r.stderr.decode('utf-8', 'replace')[:1500])
# 2. 重复 const 声明
consts = re.findall(r'^const\s+(\w+)', js, re.M)
dup = [k for k, c in collections.Counter(consts).items() if c > 1]
print('重复 const:', dup if dup else '')
# 3. onclick 引用函数是否都定义
called = set(re.findall(r'onclick="(\w+)\(', t))
defined = set(re.findall(r'(?:async\s+)?function\s+(\w+)\(', js)) | set(consts)
missing = sorted(c for c in called if c not in defined)
print('onclick 引用数:', len(called), '| 未定义:', missing if missing else '')
# 4. 重复 function 声明(同名)
fns = re.findall(r'^(?:async\s+)?function\s+(\w+)\(', js, re.M)
dupfn = [k for k, c in collections.Counter(fns).items() if c > 1]
print('重复 function:', dupfn if dupfn else '')
# 5. 关键锚点
for a in ['SY_STATUS_TXT', 'STATUS_TXT', 'syncPage()', 'infoBox', 'waitFor', 'remintToken']:
print(f' {a}:', js.count(a))