mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
This commit is contained in:
+36
@@ -517,5 +517,41 @@ describe('DeadCodeInjectionTransformer', () => {
|
||||
assert.isAtLeast(matchesLength, expectedMatchesLength);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #12 - block statement with scope-hoisting', () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
`${variableMatch} *\\(\\); *` +
|
||||
`var *${variableMatch} *= *0x2; *` +
|
||||
`function *${variableMatch} *\\(\\) *{ *} *`,
|
||||
'g'
|
||||
);
|
||||
const expectedMatchesLength: number = 5;
|
||||
|
||||
let matchesLength: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/block-statement-with-scope-hoisting.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1,
|
||||
deadCodeInjection: true,
|
||||
deadCodeInjectionThreshold: 1
|
||||
}
|
||||
);
|
||||
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
const functionMatches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(regExp);
|
||||
|
||||
if (functionMatches) {
|
||||
matchesLength = functionMatches.length;
|
||||
} });
|
||||
|
||||
it('shouldn\'t collect block statements with scope-hoisting', () => {
|
||||
assert.equal(matchesLength, expectedMatchesLength);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+15
@@ -1,22 +1,37 @@
|
||||
(function(){
|
||||
function foo () {
|
||||
var a = 1;
|
||||
inner1();
|
||||
var b = 2;
|
||||
function inner1 () {}
|
||||
var c = 3;
|
||||
}
|
||||
function bar () {
|
||||
var a = 1;
|
||||
inner2();
|
||||
var b = 2;
|
||||
function inner2 () {}
|
||||
var c = 3;
|
||||
}
|
||||
function baz () {
|
||||
var a = 1;
|
||||
inner3();
|
||||
var b = 2;
|
||||
function inner3 () {}
|
||||
var c = 3;
|
||||
}
|
||||
function bark () {
|
||||
var a = 1;
|
||||
inner4();
|
||||
var b = 2;
|
||||
function inner4 () {}
|
||||
var c = 3;
|
||||
}
|
||||
function hawk () {
|
||||
var a = 1;
|
||||
inner5();
|
||||
var b = 2;
|
||||
function inner5 () {}
|
||||
var c = 3;
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user