Negative reservedNames option doesnt work
Option for reservedNames when renameProperty option is on
Expected Behavior
reservedNames = ["^renameME"] reserved all names except "renameME"
Current Behavior
mangles every names except "renameME"
Steps to Reproduce
- reservedNames = ["^renameME"]
- Run obfuscation
JavaScript Obfuscator Edition
- JavaScript Obfuscator Open Source
Your Environment
- Obfuscator version used:
- Node version used: v24.13.0
Stack trace
none
Minimal working example that will help to reproduce issue
var JavaScriptObfuscator = require("javascript-obfuscator"); let opt1 = { target: "node", compact: false, stringArray: false, renameProperties: true, renamePropertiesMode: "safe", reservedNames: ["^renameMeOnly"], }
let code = "(function(){function pleasedontrename (){}; function renameMeOnly(){}})"
console.log(JavaScriptObfuscator.obfuscate(code, opt1).getObfuscatedCode());
Hi, the reservedNames option accepts a regexp string, so the ^ character means the start of a new line, not a negative pattern.
There's though a different issue that causes infinity loop when a proper negative pattern like ^(?!renameMeOnly$) matches all identifier names. I'll fix it
Will be released in 5.4.0 later today