120 lines
4.1 KiB
JavaScript
120 lines
4.1 KiB
JavaScript
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('Total lines:', lines.length);
|
|
|
|
// 检查常见的语法问题
|
|
console.log('\n=== Checking for common syntax issues ===\n');
|
|
|
|
// 1. 检查括号匹配
|
|
let curlyBraces = 0;
|
|
let parentheses = 0;
|
|
let squareBrackets = 0;
|
|
let inScript = false;
|
|
let inTemplate = false;
|
|
let inStyle = false;
|
|
let scriptContent = [];
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
const line = lines[i];
|
|
|
|
if (line.includes('<script')) {
|
|
inScript = true;
|
|
inTemplate = false;
|
|
inStyle = false;
|
|
} else if (line.includes('<template')) {
|
|
inTemplate = true;
|
|
inScript = false;
|
|
inStyle = false;
|
|
} else if (line.includes('<style')) {
|
|
inStyle = true;
|
|
inScript = false;
|
|
inTemplate = false;
|
|
}
|
|
|
|
if (inScript) {
|
|
scriptContent.push({ line: i + 1, content: line });
|
|
|
|
// 简单计数(不考虑字符串内的)
|
|
const openCurly = (line.match(/{/g) || []).length;
|
|
const closeCurly = (line.match(/}/g) || []).length;
|
|
curlyBraces += openCurly - closeCurly;
|
|
|
|
// 检查方法声明后是否缺少逗号
|
|
// 匹配方法声明模式: methodName() { 或 async methodName() {
|
|
if (line.match(/^\s+(async\s+)?\w+\([^)]*\)\s*{\s*$/) && !line.includes(',')) {
|
|
// 检查下一行是否是新方法声明
|
|
if (i + 1 < lines.length) {
|
|
const nextLine = lines[i + 1];
|
|
if (!nextLine.trim().startsWith('//') &&
|
|
!nextLine.trim().startsWith('}') &&
|
|
!nextLine.trim().startsWith('return') &&
|
|
!nextLine.includes('this.') &&
|
|
!nextLine.trim().startsWith('const') &&
|
|
!nextLine.trim().startsWith('let') &&
|
|
!nextLine.trim().startsWith('var') &&
|
|
nextLine.trim() !== '') {
|
|
console.log(`Line ${i + 1}: Method declaration may be missing comma: ${line.trim()}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 检查方法结束后的逗号
|
|
if (line.match(/^\s+},\s*$/) && i > 0) {
|
|
const prevLine = lines[i - 1];
|
|
// 如果前一行是 return 或其他语句,这是正常的
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log('\n=== Bracket balance check ===');
|
|
console.log('Curly braces balance:', curlyBraces, curlyBraces === 0 ? '(balanced)' : '(UNBALANCED!)');
|
|
|
|
// 2. 检查方法声明
|
|
console.log('\n=== Checking method declarations ===');
|
|
const methodRegex = /^\s+(async\s+)?(\w+)\s*\([^)]*\)\s*{/;
|
|
let methods = [];
|
|
let inMethods = false;
|
|
for (let i = 0; i < lines.length; i++) {
|
|
if (lines[i].includes('methods:')) {
|
|
inMethods = true;
|
|
console.log('Found methods: at line', i + 1);
|
|
}
|
|
if (inMethods && lines[i].includes('},') && lines[i].trim() === '},') {
|
|
const nextLine = lines[i + 1] || '';
|
|
if (!nextLine.trim().startsWith('//') && !nextLine.trim().startsWith('}') && !nextLine.trim().startsWith(']') && nextLine.trim() !== '') {
|
|
console.log(`Line ${i + 1}: End of methods object?`);
|
|
console.log(` Line content: ${lines[i]}`);
|
|
console.log(` Next line: ${nextLine}`);
|
|
}
|
|
}
|
|
if (inMethods && methodRegex.test(lines[i])) {
|
|
const match = lines[i].match(methodRegex);
|
|
methods.push({ name: match[2], line: i + 1 });
|
|
}
|
|
}
|
|
|
|
console.log('\n=== Methods found ===');
|
|
methods.forEach(m => console.log(`Line ${m.line}: ${m.name}`));
|
|
|
|
// 3. 检查是否有明显的错误
|
|
console.log('\n=== Checking for obvious errors ===');
|
|
for (let i = 0; i < lines.length; i++) {
|
|
const line = lines[i];
|
|
// 检查是否有重复的声明
|
|
if (line.includes('components:') && lines.slice(i + 1, i + 20).some(l => l.includes('components:'))) {
|
|
console.log(`Line ${i + 1}: Duplicate components declaration?`);
|
|
}
|
|
if (line.includes('props:') && lines.slice(i + 1, i + 30).some(l => l.includes('props:'))) {
|
|
console.log(`Line ${i + 1}: Duplicate props declaration?`);
|
|
}
|
|
}
|
|
|
|
// 4. 特别检查 generateIsbn 和 resetFormData 附近的代码
|
|
console.log('\n=== Checking around generateIsbn and resetFormData ===');
|
|
for (let i = 1930; i < 2000 && i < lines.length; i++) {
|
|
console.log(`Line ${i + 1}: ${lines[i]}`);
|
|
}
|