Support for class static blocks

This commit is contained in:
sanex
2022-01-29 14:57:21 +03:00
parent ac3c34fe77
commit 6b8ead0b2b
11 changed files with 115 additions and 15 deletions
@@ -984,6 +984,42 @@ describe('JavaScriptObfuscator', () => {
});
});
describe('Class static block support', () => {
const regExp: RegExp = new RegExp(
'let _0x(\\w){4,6} *= *0x1; *' +
'class _0x(\\w){4,6} *{ *' +
'static *\\[\'_0x(\\w){4,6}\']; *' +
'static *{ *' +
'let _0x(\\w){4,6} *= *0x2; *' +
'_0x(\\w){4,6}\\[\'_0x(\\w){4,6}\'] *= *0x3; *' +
'_0x(\\w){4,6} *= *0x4; *' +
'_0x(\\w){4,6} *= *0x5; *' +
'} *' +
'}'
);
let obfuscatedCode: string;
beforeEach(() => {
const code: string = readFileAsString(__dirname + '/fixtures/class-static-block-support-1.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
renameGlobals: true,
renameProperties: true
}
).getObfuscatedCode();
console.log(obfuscatedCode);
});
it('should support class static block await', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('Private identifiers support', () => {
const regExp: RegExp = new RegExp(
'class Foo *{ *' +
@@ -0,0 +1,11 @@
let foo = 1;
class Foo {
static abc;
static {
let bar = 2;
Foo.abc = 3;
foo = 4;
bar = 5;
}
}