test-single-file.cjs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const fs = require('fs');
  2. const path = require('path');
  3. const filePath = path.resolve(__dirname, '../src/components/anthology/AnthologyList.tsx');
  4. console.log('测试文件:', filePath);
  5. console.log('文件存在:', fs.existsSync(filePath));
  6. if (fs.existsSync(filePath)) {
  7. const lines = fs.readFileSync(filePath, 'utf-8').split('\n');
  8. console.log('\n第 21 行 (索引 20):');
  9. console.log('内容:', JSON.stringify(lines[20]));
  10. console.log('长度:', lines[20].length);
  11. // 测试匹配
  12. const pattern = /^(\s*)import\s+(\w+)\s*,\s*\{([^}]+)\}\s*from\s*(['"][^'"]+['"])\s*;?\s*$/;
  13. const match = lines[20].match(pattern);
  14. console.log('\n匹配结果:', match ? '✅ 成功' : '❌ 失败');
  15. if (match) {
  16. console.log('捕获:', {
  17. indent: match[1],
  18. defaultName: match[2],
  19. imports: match[3],
  20. source: match[4],
  21. });
  22. }
  23. // 模拟脚本的查找逻辑
  24. console.log('\n=== 模拟脚本查找 ===');
  25. const errorLineNum = 21;
  26. const errorLineIndex = errorLineNum - 1; // 20
  27. let startIndex = -1;
  28. for (let i = errorLineIndex; i >= Math.max(0, errorLineIndex - 30); i--) {
  29. console.log(`检查第 ${i+1} 行:`, lines[i].substring(0, 50));
  30. if (lines[i].match(/^\s*import\s/)) {
  31. startIndex = i;
  32. console.log(` → 找到 import 起始: 第 ${i+1} 行`);
  33. break;
  34. }
  35. if (i < errorLineIndex && lines[i].trim() === '') {
  36. console.log(' → 遇到空行,停止查找');
  37. break;
  38. }
  39. }
  40. console.log('\n最终找到的起始行:', startIndex === -1 ? '未找到' : `第 ${startIndex + 1} 行`);
  41. if (startIndex !== -1) {
  42. console.log('起始行内容:', lines[startIndex]);
  43. }
  44. }