原始资料 · reports/evidence-documentation/frontend-semantic-checker.txt · 以可阅读文本展示,HTML 与脚本不会在页面中执行。
const fs=require('fs'),path=require('path');const ts=require(process.cwd()+'/frontend/node_modules/typescript');const postcss=require(process.cwd()+'/frontend/node_modules/postcss');const crypto=require('crypto');const base=process.argv[2];const output={}; function hash(text){return crypto.createHash('sha256').update(text).digest('hex')} function astFingerprint(p){const sf=ts.createSourceFile(p,fs.readFileSync(p,'utf8'),ts.ScriptTarget.Latest,true);if(sf.parseDiagnostics.length)throw Error('syntax '+p);const nodes=[];function visit(n){nodes.push([n.kind,n.kind!==ts.SyntaxKind.SourceFile&&typeof n.text==='string'?n.text:null]);ts.forEachChild(n,visit)}visit(sf);return hash(JSON.stringify(nodes))} function cssFingerprint(p){const root=postcss.parse(fs.readFileSync(p,'utf8'));root.walkComments(n=>n.remove());return hash(JSON.stringify(root.toJSON(),(k,v)=>['source','raws','inputs'].includes(k)?undefined:v))} for(const top of ['frontend/src','frontend/tests','frontend/scripts']){function walk(d){for(const ent of fs.readdirSync(d,{withFileTypes:true})){const p=path.join(d,ent.name);if(ent.isDirectory())walk(p);else if(/\.(ts|tsx|mjs|css)$/.test(p)){const fp=p.endsWith('.css')?cssFingerprint:astFingerprint;const old=fp(path.join(base,p)),now=fp(p);if(old!==now)throw Error('semantic AST changed: '+p);output[p]=now}}}walk(top)} console.log(JSON.stringify(output,null,2)); |