second commit
This commit is contained in:
54
debug-jsx.js
Normal file
54
debug-jsx.js
Normal file
@@ -0,0 +1,54 @@
|
||||
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(/<div/g) || []).length;
|
||||
const closeDivs = (content.match(/<\/div>/g) || []).length;
|
||||
const openProtectedRoute = (content.match(/<ProtectedRoute/g) || []).length;
|
||||
const closeProtectedRoute = (content.match(/<\/ProtectedRoute>/g) || []).length;
|
||||
|
||||
console.log(`📊 标签统计:`);
|
||||
console.log(` - <div>: ${openDivs}`);
|
||||
console.log(` - </div>: ${closeDivs}`);
|
||||
console.log(` - <ProtectedRoute: ${openProtectedRoute}`);
|
||||
console.log(` - </ProtectedRoute>: ${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('<div')) {
|
||||
divPositions.push({ line: index + 1, type: 'open', content: line.trim() });
|
||||
}
|
||||
if (line.includes('</div>')) {
|
||||
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);
|
||||
Reference in New Issue
Block a user