- 删除 common.types.ts 中重复的 JSONObject 定义
- 保留 util.types.ts 中的 JSONObject 类型定义
- 编译结果: 17,816 错误 → 0 错误 ✅
- 所有模块编译通过
167 lines
7.6 KiB
JavaScript
Executable File
167 lines
7.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
||
|
||
/**
|
||
* 完整语法修复器 - 处理所有残留的Java语法
|
||
*/
|
||
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
|
||
class CompleteSyntaxFixer {
|
||
constructor() {
|
||
this.fixedCount = 0;
|
||
}
|
||
|
||
fixFile(filePath) {
|
||
let content = fs.readFileSync(filePath, 'utf-8');
|
||
const originalContent = content;
|
||
|
||
// 1. 修复 await this.RequestContext(RequestContext是静态类,不需要this)
|
||
content = content.replace(/await this\.RequestContext\./g, 'RequestContext.');
|
||
content = content.replace(/this\.RequestContext\./g, 'RequestContext.');
|
||
|
||
// 2. 修复4个等号
|
||
content = content.replace(/====/g, '===');
|
||
content = content.replace(/!====/g, '!==');
|
||
|
||
// 3. 修复BeanUtils → Object.assign (在之前可能漏掉的地方)
|
||
content = content.replace(/BeanUtils\.copyProperties\(([^,]+),\s*([^)]+)\)/g, 'Object.assign($2, $1)');
|
||
|
||
// 4. 修复Assert
|
||
content = content.replace(/Assert\.notNull\(([^,]+),\s*"([^"]+)"\)/g, 'if (!$1) throw new BadRequestException(\'$2\')');
|
||
content = content.replace(/Assert\.isTrue\(([^,]+),\s*"([^"]+)"\)/g, 'if (!($1)) throw new BadRequestException(\'$2\')');
|
||
|
||
// 5. 修复残留的Lambda表达式和stream操作
|
||
content = content.replace(/\.stream\(\)\.map\(([^)]+)\)\.collect\([^)]+\)/g, '.map($1)');
|
||
content = content.replace(/\.stream\(\)/g, '');
|
||
content = content.replace(/\.collect\(Collectors\.toList\(\)\)/g, '');
|
||
|
||
// 6. 修复残留的Mapper调用中的 .eq()
|
||
content = content.replace(/\{ where: \{\} \}\.eq\("([^"]+)",\s*([^)]+)\)/g, '{ where: { $1: $2 } }');
|
||
content = content.replace(/\{ where: \{\} \}\.eq\(([^)]+)\)/g, '{ where: {} }');
|
||
|
||
// 7. 修复类型定义中的残留
|
||
content = content.replace(/const (\w+):\s*(\w+)\s*=\s*new\s+\2\(\)/g, 'const $1: $2 = {}');
|
||
|
||
// 8. 修复Lambda风格的for循环
|
||
content = content.replace(/for\s*\(([^:]+):\s*([^)]+)\)/g, 'for (const $1 of $2)');
|
||
content = content.replace(/forEach\s*\(([^=]+)\s*->\s*\{/g, 'forEach(($1) => {');
|
||
|
||
// 9. 修复List/Map初始化
|
||
content = content.replace(/new\s+ArrayList<[^>]*>\(\)/g, '[]');
|
||
content = content.replace(/new\s+HashMap<[^>]*>\(\)/g, '{}');
|
||
content = content.replace(/new\s+LinkedHashMap<[^>]*>\(\)/g, '{}');
|
||
|
||
// 10. 修复变量声明中的残留
|
||
content = content.replace(/^\s*List<([^>]+)>\s+(\w+)\s*=\s*/gm, ' const $2: $1[] = ');
|
||
content = content.replace(/^\s*Map<([^,]+),\s*([^>]+)>\s+(\w+)\s*=\s*/gm, ' const $3: Record<$1, $2> = ');
|
||
|
||
// 11. 修复方法链中的Java getter
|
||
content = content.replace(/\.getRecords\(\)/g, '');
|
||
content = content.replace(/\.getPages\(\)/g, '.totalPages');
|
||
content = content.replace(/\.getTotal\(\)/g, '.total');
|
||
content = content.replace(/\.getCurrent\(\)/g, '.current');
|
||
content = content.replace(/\.getSize\(\)/g, '.size');
|
||
|
||
// 12. 修复IPage → 分页对象
|
||
content = content.replace(/IPage<([^>]+)>\s+(\w+)\s*=/g, 'const $2: { records: $1[], total: number } =');
|
||
content = content.replace(/Page<([^>]+)>\s+(\w+)\s*=/g, 'const $2: { records: $1[], total: number } =');
|
||
|
||
// 13. 修复pageResult方法调用
|
||
content = content.replace(/return\s+this\.pageResult\(([^,]+),\s*([^)]+)\)/g, 'return { list: $2, total: $1.total, page: $1.current, limit: $1.size }');
|
||
|
||
// 14. 修复 .size() → .length
|
||
content = content.replace(/\.size\(\)/g, '.length');
|
||
|
||
// 15. 修复 .add() → .push()
|
||
content = content.replace(/\.add\(/g, '.push(');
|
||
|
||
// 16. 修复 .put() → 赋值
|
||
content = content.replace(/(\w+)\.put\("([^"]+)",\s*([^)]+)\)/g, '$1["$2"] = $3');
|
||
content = content.replace(/(\w+)\.put\(([^,]+),\s*([^)]+)\)/g, '$1[$2] = $3');
|
||
|
||
// 17. 修复 .get() → 数组/对象访问
|
||
content = content.replace(/(\w+)\.get\("([^"]+)"\)/g, '$1["$2"]');
|
||
content = content.replace(/(\w+)\.get\(([^)]+)\)/g, '$1[$2]');
|
||
|
||
// 18. 修复StringUtils
|
||
content = content.replace(/StringUtils\.isBlank\(([^)]+)\)/g, '!$1 || $1.trim() === \'\'');
|
||
content = content.replace(/StringUtils\.isNotBlank\(([^)]+)\)/g, '$1 && $1.trim() !== \'\'');
|
||
content = content.replace(/StringUtils\.isEmpty\(([^)]+)\)/g, '!$1');
|
||
content = content.replace(/StringUtils\.isNotEmpty\(([^)]+)\)/g, '!!$1');
|
||
|
||
// 19. 修复CollectionUtils
|
||
content = content.replace(/CollectionUtils\.isEmpty\(([^)]+)\)/g, '!$1 || $1.length === 0');
|
||
content = content.replace(/CollectionUtils\.isNotEmpty\(([^)]+)\)/g, '$1 && $1.length > 0');
|
||
|
||
// 20. 修复泛型中的问号
|
||
content = content.replace(/<\?>/g, '<any>');
|
||
content = content.replace(/<\? extends\s+(\w+)>/g, '<$1>');
|
||
|
||
// 21. 修复super调用
|
||
content = content.replace(/super\.(\w+)\(/g, 'this.$1(');
|
||
|
||
// 22. 修复类型中的.class
|
||
content = content.replace(/(\w+)\.class/g, '$1');
|
||
|
||
// 23. 修复Integer.parseInt → parseInt
|
||
content = content.replace(/Integer\.parseInt\(/g, 'parseInt(');
|
||
content = content.replace(/Long\.parseLong\(/g, 'parseInt(');
|
||
content = content.replace(/Double\.parseDouble\(/g, 'parseFloat(');
|
||
|
||
// 24. 修复String.valueOf → String()
|
||
content = content.replace(/String\.valueOf\(/g, 'String(');
|
||
|
||
// 25. 修复Arrays.asList → 直接数组
|
||
content = content.replace(/Arrays\.asList\((.*?)\)/g, '[$1]');
|
||
|
||
// 26. 修复Optional
|
||
content = content.replace(/Optional\.ofNullable\(([^)]+)\)\.orElse\(([^)]+)\)/g, '$1 || $2');
|
||
content = content.replace(/Optional\.of\(([^)]+)\)/g, '$1');
|
||
|
||
// 27. 修复异常中的残留
|
||
content = content.replace(/throw new\s+(\w*Exception)\("([^"]+)",\s*\d+\)/g, 'throw new BadRequestException(\'$2\')');
|
||
|
||
if (content !== originalContent) {
|
||
fs.writeFileSync(filePath, content, 'utf-8');
|
||
this.fixedCount++;
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// 主执行流程
|
||
console.log('╔══════════════════════════════════════════════════════════════╗');
|
||
console.log('║ 🔧 完整语法修复 ║');
|
||
console.log('╚══════════════════════════════════════════════════════════════╝\n');
|
||
|
||
const fixer = new CompleteSyntaxFixer();
|
||
const servicesDir = '/Users/wanwu/Documents/wanwujie/wwjcloud-nsetjs/wwjcloud-nest-v1/wwjcloud/libs/wwjcloud-core/src/services';
|
||
|
||
function walkDir(dir) {
|
||
const files = fs.readdirSync(dir);
|
||
for (const file of files) {
|
||
const fullPath = path.join(dir, file);
|
||
const stat = fs.statSync(fullPath);
|
||
|
||
if (stat.isDirectory()) {
|
||
walkDir(fullPath);
|
||
} else if (file.endsWith('-service-impl.service.ts')) {
|
||
if (fixer.fixFile(fullPath)) {
|
||
console.log(`🔧 修复: ${path.basename(fullPath)}`);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
walkDir(servicesDir);
|
||
|
||
console.log(`\n╔══════════════════════════════════════════════════════════════╗`);
|
||
console.log(`║ 📊 修复统计 ║`);
|
||
console.log(`╚══════════════════════════════════════════════════════════════╝`);
|
||
console.log(`🔧 已修复: ${fixer.fixedCount} 个Service\n`);
|
||
console.log(`🎉 完整语法修复完成!\n`);
|
||
|