mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Add renameProperties support for private class fields and methods (#1393)
This commit is contained in:
@@ -910,9 +910,7 @@ describe('JavaScriptObfuscator', () => {
|
||||
});
|
||||
|
||||
describe('Private identifiers support', () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
'class Foo *{ *' + '#bar *= *0x1; *' + "\\['method'] *\\(\\) *{ *" + 'this\.#bar *= *0x2;' + '} *' + '}'
|
||||
);
|
||||
const variableMatch: string = '_0x([a-f0-9]){4,6}';
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
@@ -925,8 +923,20 @@ describe('JavaScriptObfuscator', () => {
|
||||
}).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should support private identifiers', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
it('should rename private field', () => {
|
||||
assert.match(obfuscatedCode, new RegExp(`#${variableMatch} *= *0x1`));
|
||||
});
|
||||
|
||||
it('should rename private field access', () => {
|
||||
assert.match(obfuscatedCode, new RegExp(`this\\.#${variableMatch} *= *0x2`));
|
||||
});
|
||||
|
||||
it('should rename private method declaration', () => {
|
||||
assert.match(obfuscatedCode, new RegExp(`#${variableMatch}\\(\\) *\\{`));
|
||||
});
|
||||
|
||||
it('should rename private method call', () => {
|
||||
assert.match(obfuscatedCode, new RegExp(`this\\.#${variableMatch}\\(\\)`));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -4,4 +4,13 @@ class Foo {
|
||||
method() {
|
||||
this.#bar = 2;
|
||||
}
|
||||
}
|
||||
|
||||
#privateMethod() {
|
||||
return this.#bar;
|
||||
}
|
||||
|
||||
run() {
|
||||
this.method();
|
||||
return this.#privateMethod();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user