Skip to content

Added test for reservedNames bug in classes #1279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,41 @@ describe('JavaScriptObfuscator', () => {
});
});

describe('class function not obfuscated if option "reservedNames', () => {
let obfuscations: string[];

beforeEach(() => {
obfuscations = []
const code: string = readFileAsString(__dirname + '/fixtures/class-with-function.js');
for (let i = 0; i < 100; i++) {
const obfuscatedCode:string = JavaScriptObfuscator.obfuscate(
code,
{
controlFlowFlattening: true,
deadCodeInjection: true,
reservedNames: ['bar']
}
).getObfuscatedCode();

obfuscations.push(obfuscatedCode)
}
});

it('class should always have "bar" function not obfuscated', () => {
let obfuscated: number = 0;
let notObfuscated: number = 0;
for (const codeAsString of obfuscations) {
if (codeAsString.includes("['bar']")) { notObfuscated++; }
else { obfuscated++; }

}

console.log({obfuscated, notObfuscated})
assert.equal(obfuscated, 0)
assert.equal(notObfuscated, obfuscations.length)
});
});

describe('invalid source code type', () => {
let obfuscatedCode: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Foo{
bar(){
console.log(1)
baz()
}
}