mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added test for function default parameter as identifier
This commit is contained in:
+35
@@ -684,6 +684,41 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parameter default value', () => {
|
||||
describe('Variant #1: default parameter as identifier', () => {
|
||||
const variableDeclarationRegExp: RegExp = /var bar *= *0x1;/;
|
||||
const functionParameterRegExp: RegExp = /function func *\(_0x[a-f0-9]{4,6} *= *bar\) *\{/;
|
||||
const functionBodyRegExp: RegExp = /return *_0x[a-f0-9]{4,6} *\+ *bar;/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/default-parameter-as-identifier.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('match #1: shouldn transform variable declaration', () => {
|
||||
assert.match(obfuscatedCode, variableDeclarationRegExp);
|
||||
});
|
||||
|
||||
it('match #2: shouldn transform function parameters', () => {
|
||||
assert.match(obfuscatedCode, functionParameterRegExp);
|
||||
});
|
||||
|
||||
it('match #3: shouldn transform function body', () => {
|
||||
assert.match(obfuscatedCode, functionBodyRegExp);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('ignored identifier names set', () => {
|
||||
describe('Variant #1: avoid to add `ObjectPattern` identifier to the set when same identifier exist in function parameter', () => {
|
||||
const functionBodyRegExp: RegExp = /\[]\['find']\(\({bar: *_0x[a-f0-9]{4,6}}\) *=> *_0x[a-f0-9]{4,6}\);/;
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
var bar = 1;
|
||||
function func (foo = bar) {
|
||||
return foo + bar;
|
||||
}
|
||||
Reference in New Issue
Block a user