Added test for function default parameter as identifier

This commit is contained in:
sanex3339
2020-01-18 11:23:52 +03:00
parent b776df8f90
commit ee8c42fec0
2 changed files with 39 additions and 0 deletions
@@ -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}\);/;
@@ -0,0 +1,4 @@
var bar = 1;
function func (foo = bar) {
return foo + bar;
}