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

// 尝试使用 @vue/compiler-sfc 或 vue-template-compiler
let compiler;
try {
  compiler = require('@vue/compiler-sfc');
  console.log('Using @vue/compiler-sfc');
} catch (e) {
  try {
    compiler = require('vue-template-compiler');
    console.log('Using vue-template-compiler');
  } catch (e2) {
    console.log('No Vue compiler available');
    console.log('Error:', e.message);
    console.log('Error2:', e2.message);
    process.exit(0);
  }
}

if (compiler.parse) {
  console.log('\nParsing file...\n');
  try {
    const result = compiler.parse(content, {
      filename: 'PhotoUploadForm.vue'
    });
    
    if (result.errors && result.errors.length > 0) {
      console.log('Parse errors:');
      result.errors.forEach(err => {
        console.log(err);
      });
    } else {
      console.log('File parsed successfully!');
    }
    
    if (result.descriptor) {
      console.log('\nScript setup:', result.descriptor.scriptSetup ? 'yes' : 'no');
      console.log('Script:', result.descriptor.script ? 'yes' : 'no');
      console.log('Template:', result.descriptor.template ? 'yes' : 'no');
      console.log('Style blocks:', result.descriptor.styles.length);
    }
  } catch (e) {
    console.log('Parse error:', e.message);
  }
}
