Files
cursornew2026/fix_syntax.js

60 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 修复语法并清理属性访问
*/
const fs = require('fs');
const inputPath = 'D:/temp/破解/cursorpro-0.4.5/deobfuscated_full/extension/out/webview/provider.js';
console.log('智能清理属性访问...');
let code = fs.readFileSync(inputPath, 'utf8');
console.log('原始大小:', (code.length / 1024).toFixed(2), 'KB');
// 1. 方法定义: async ['_method']() -> async _method()
code = code.replace(/(async\s+)\[(['"])([a-zA-Z_$][a-zA-Z0-9_$]*)\2\]\s*\(/g, '$1$3(');
// 2. 方法定义: } ['_method']()
code = code.replace(/(\}\s*)\[(['"])([a-zA-Z_$][a-zA-Z0-9_$]*)\2\]\s*\(/g, '$1$3(');
// 3. 独立的方法定义 (行首)
code = code.replace(/(\n\s*)\[(['"])([a-zA-Z_$][a-zA-Z0-9_$]*)\2\]\s*\(/g, '$1$3(');
// 4. 普通属性访问 + 方法调用: obj['prop']() -> obj.prop()
code = code.replace(/\[(['"])([a-zA-Z_$][a-zA-Z0-9_$]*)\1\]\s*\(/g, '.$2(');
// 5. 普通属性访问: obj['prop'] -> obj.prop (非方法调用)
code = code.replace(/\[(['"])([a-zA-Z_$][a-zA-Z0-9_$]*)\1\]/g, '.$2');
// 6. 布尔值简化
code = code.replace(/!!\[\]/g, 'true');
code = code.replace(/!\[\]/g, 'false');
// 7. 修复可能产生的语法错误: 独立的 .method( -> method(
// 这种情况出现在类方法定义中
const lines = code.split('\n');
for (let i = 0; i < lines.length; i++) {
// 如果一行以 .methodName( 开头(可能有空格),这通常是方法定义
const match = lines[i].match(/^(\s*)\.([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/);
if (match) {
lines[i] = match[1] + match[2] + '(' + lines[i].slice(match[0].length);
}
}
code = lines.join('\n');
fs.writeFileSync(inputPath, code);
console.log('新大小:', (code.length / 1024).toFixed(2), 'KB');
// 验证
console.log('\n验证语法问题:');
const badAsync = (code.match(/async\s+\.\w+\s*\(/g) || []).length;
const badMethod = (code.match(/}\s*\.\w+\s*\(/g) || []).length;
const emptyAsync = (code.match(/async\s+\(\)\s*\{/g) || []).length;
console.log(' async .xxx():', badAsync);
console.log(' } .xxx():', badMethod);
console.log(' async () {}:', emptyAsync);
if (badAsync + badMethod + emptyAsync === 0) {
console.log('\n✅ 语法检查通过!');
} else {
console.log('\n⚠ 仍有语法问题需要处理');
}