mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added optional-chaining support
This commit is contained in:
@@ -682,6 +682,32 @@ describe('JavaScriptObfuscator', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Optional chaining support', () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
'const _0x(\\w){4,6} *= *{ *' +
|
||||
'\'bar\': *\\(\\) *=> *{} *' +
|
||||
'}; *' +
|
||||
'_0x(\\w){4,6}\\?\\.\\[\'bar\']\\?\\.\\(\\);'
|
||||
);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
beforeEach(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/optional-chaining-support.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should support optional chaining', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mangled identifier names generator', () => {
|
||||
const regExp: RegExp = /var c *= *0x1/;
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
function test() {
|
||||
const foo = {
|
||||
bar: () => {}
|
||||
};
|
||||
|
||||
foo?.bar?.();
|
||||
}
|
||||
Reference in New Issue
Block a user