const fs = require('fs'); const path = 'D:\\project\\zhizhu\\components\\PhotoUploadForm.vue'; const content = fs.readFileSync(path, 'utf8'); const lines = content.split('\n'); console.log('=== Final validation ===\n'); // 检查文件末尾结构 console.log('File ending structure:'); for (let i = lines.length - 30; i < lines.length; i++) { if (lines[i].includes('') || lines[i].includes('') || lines[i].includes('};') || lines[i].includes('},') || lines[i].trim() === '}') { console.log(`Line ${i + 1}: ${lines[i]}`); } } // 精确的括号计数 let braceCount = 0; let exportStart = -1; let scriptEnd = -1; for (let i = 0; i < lines.length; i++) { if (lines[i].includes('export default {')) { exportStart = i; } if (lines[i].includes('')) { scriptEnd = i; break; } } // 从 export default 开始计数 if (exportStart >= 0 && scriptEnd >= 0) { for (let i = exportStart; i <= scriptEnd; i++) { const line = lines[i]; // 跳过 import(export 之后不应该有 import) if (line.includes('import ')) continue; const codeOnly = line.replace(/\/\/.*$/, '').replace(/\/\*.*?\*\//g, ''); const noStrings = codeOnly.replace(/'[^']*'/g, '""').replace(/"[^"]*"/g, '""').replace(/`[^`]*`/g, '""'); const opens = (noStrings.match(/{/g) || []).length; const closes = (noStrings.match(/}/g) || []).length; braceCount += opens - closes; } console.log(`\nBrace count from export default to : ${braceCount}`); console.log(braceCount === 0 ? '✓ Balanced!' : '✗ Unbalanced!'); } // 验证具体的方法结束和 methods 结束 console.log('\n=== Checking methods end ==='); for (let i = lines.length - 10; i < lines.length; i++) { console.log(`Line ${i + 1}: "${lines[i]}"`); }