const fs = require('fs');
const path = require('path');
function debugJSX() {
try {
console.log('🔍 调试 JSX 结构...');
const profilePath = path.join(__dirname, 'src', 'app', 'profile', 'page.tsx');
const content = fs.readFileSync(profilePath, 'utf8');
// 计算各种标签
const openDivs = (content.match(/
/g) || []).length;
const openProtectedRoute = (content.match(/
/g) || []).length;
console.log(`📊 标签统计:`);
console.log(` - : ${openDivs}`);
console.log(` -
: ${closeDivs}`);
console.log(` - : ${closeProtectedRoute}`);
console.log(` - div 标签平衡: ${openDivs === closeDivs ? '✅' : '❌'}`);
console.log(` - ProtectedRoute 标签平衡: ${openProtectedRoute === closeProtectedRoute ? '✅' : '❌'}`);
// 查找所有 div 标签的位置
const lines = content.split('\n');
const divPositions = [];
lines.forEach((line, index) => {
if (line.includes('')) {
divPositions.push({ line: index + 1, type: 'close', content: line.trim() });
}
});
console.log(`\n📍 div 标签位置:`);
divPositions.forEach(pos => {
console.log(` 第${pos.line}行: ${pos.type === 'open' ? '开始' : '结束'} - ${pos.content}`);
});
return openDivs === closeDivs && openProtectedRoute === closeProtectedRoute;
} catch (error) {
console.error('❌ 调试出错:', error.message);
return false;
}
}
// 运行调试
const result = debugJSX();
console.log(`\n🎯 结果: ${result ? '✅ 结构正确' : '❌ 结构有问题'}`);
process.exit(result ? 0 : 1);