const fs = require('fs');
const path = 'D:\\project\\zhizhu\\components\\PhotoUploadForm.vue';
const content = fs.readFileSync(path, 'utf8');

// 提取 script 部分
const scriptMatch = content.match(/<script[^>]*>([\s\S]*?)<\/script>/);
if (!scriptMatch) {
  console.log('Cannot find script section');
  process.exit(1);
}

const scriptContent = scriptMatch[1];

// 使用 acorn 解析（如果可用）
try {
  const acorn = require('acorn');
  const ast = acorn.parse(scriptContent, {
    ecmaVersion: 2020,
    sourceType: 'module',
    locations: true,
    onInsertedSemicolon: (start, end) => {
      console.log(`Inserted semicolon at ${start}-${end}`);
    }
  });
  console.log('Script parsed successfully!');
} catch (e) {
  console.log('Parse Error:', e.message);
  if (e.loc) {
    console.log(`Error location: line ${e.loc.line}, column ${e.loc.column}`);
    
    // 显示错误附近的代码
    const lines = scriptContent.split('\n');
    const startLine = Math.max(0, e.loc.line - 5);
    const endLine = Math.min(lines.length, e.loc.line + 5);
    
    console.log('\nCode around error:');
    for (let i = startLine; i < endLine; i++) {
      const marker = (i + 1 === e.loc.line) ? '>>>' : '   ';
      console.log(`${marker} ${i + 1}: ${lines[i]}`);
    }
  }
}
