59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
const fs = require('fs');
|
|
const path = 'D:\\project\\zhizhu\\components\\PhotoUploadForm.vue';
|
|
const content = fs.readFileSync(path, 'utf8');
|
|
|
|
try {
|
|
const compiler = require('vue-template-compiler');
|
|
|
|
// 使用 compile 方法检查模板
|
|
const scriptMatch = content.match(/<script[^>]*>([\s\S]*?)<\/script>/);
|
|
const templateMatch = content.match(/<template>([\s\S]*?)<\/template>/);
|
|
|
|
if (templateMatch) {
|
|
console.log('Checking template...\n');
|
|
const templateResult = compiler.compile(templateMatch[1], {
|
|
filename: 'PhotoUploadForm.vue'
|
|
});
|
|
|
|
if (templateResult.errors && templateResult.errors.length > 0) {
|
|
console.log('Template errors:');
|
|
templateResult.errors.forEach(err => console.log(' ' + err));
|
|
} else {
|
|
console.log('Template: OK');
|
|
}
|
|
|
|
if (templateResult.tips && templateResult.tips.length > 0) {
|
|
console.log('\nTemplate tips:');
|
|
templateResult.tips.forEach(tip => console.log(' ' + tip));
|
|
}
|
|
}
|
|
|
|
// 使用 parseComponent 检查整个文件
|
|
console.log('\nParsing component...\n');
|
|
const sfcResult = compiler.parseComponent(content, {
|
|
filename: 'PhotoUploadForm.vue'
|
|
});
|
|
|
|
console.log('Script content length:', sfcResult.script ? sfcResult.script.content.length : 'N/A');
|
|
console.log('Template content length:', sfcResult.template ? sfcResult.template.content.length : 'N/A');
|
|
console.log('Styles count:', sfcResult.styles.length);
|
|
|
|
// 尝试用 acorn 解析 script
|
|
if (sfcResult.script) {
|
|
console.log('\nTrying to parse script with acorn...');
|
|
try {
|
|
const acorn = require('acorn');
|
|
acorn.parse(sfcResult.script.content, {
|
|
ecmaVersion: 2020,
|
|
sourceType: 'module'
|
|
});
|
|
console.log('Script: OK');
|
|
} catch (e) {
|
|
console.log('Acorn not available, trying direct eval check...');
|
|
}
|
|
}
|
|
|
|
} catch (e) {
|
|
console.log('Error:', e.message);
|
|
}
|