daShangDao_miniProgram/temp_methods_trace.js
2026-06-15 16:37:57 +08:00

55 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fs = require('fs');
const path = 'D:\\project\\zhizhu\\components\\PhotoUploadForm.vue';
const content = fs.readFileSync(path, 'utf8');
const lines = content.split('\n');
// 只追踪 methods 区域398-1994
console.log('=== Methods section brace tracking ===\n');
let braceCount = 1; // 假设进入 methods 时 braceCount=1从 methods: { 的 { 开始)
for (let i = 398; i <= 1994; i++) {
const line = lines[i];
// 跳过注释和字符串中的括号
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;
const prevCount = braceCount;
braceCount += opens - closes;
// 显示变化
if (opens - closes !== 0) {
console.log(`Line ${i + 1}: ${opens - closes > 0 ? '+' : ''}${opens - closes} (count: ${prevCount}${braceCount}) ${line.trim().substring(0, 50)}`);
}
// 检查异常
if (braceCount < 1) {
console.log(`\n!!! WARNING: braceCount dropped below 1 at line ${i + 1}`);
console.log(`!!! This means there's an extra } somewhere`);
console.log(`!!! Line: ${line}`);
console.log(`!!! Context (lines ${i - 5} to ${i + 5}):`);
for (let j = i - 5; j <= i + 5; j++) {
console.log(` Line ${j + 1}: ${lines[j]}`);
}
break;
}
}
console.log(`\nFinal braceCount after methods: ${braceCount}`);
console.log(`Expected: 1 (after methods: { and before },)`);
console.log(`If count > 1: there's extra { somewhere`);
console.log(`If count < 1: there's extra } somewhere`);
// 简单统计 methods 内所有方法
console.log('\n=== Methods declarations ===\n');
for (let i = 398; i <= 1994; i++) {
const line = lines[i];
const match = line.match(/^\s+(async\s+)?(\w+)\s*\([^)]*\)\s*{/);
if (match && !['if', 'for', 'while', 'switch', 'catch'].includes(match[2])) {
console.log(`Line ${i + 1}: ${match[2]}`);
}
}