|
@@ -299,5 +299,72 @@ describe('MangledIdentifierNamesGenerator', () => {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ describe('Variant #3: Should generate different names set for different lexical scopes: nested functions', () => {
|
|
|
|
+ describe('Variant #1: `renameGlobals` option is disabled', () => {
|
|
|
|
+ const regExp: RegExp = new RegExp(`` +
|
|
|
|
+ `var foo *= *'abc'; *` +
|
|
|
|
+ `function bar *\\(a, *b\\) *{` +
|
|
|
|
+ `function c *\\(e, *f\\) *{ *} *` +
|
|
|
|
+ `function d *\\(e, *f\\) *{ *} *` +
|
|
|
|
+ `} *` +
|
|
|
|
+ `function baz *\\(a, *b\\) *{` +
|
|
|
|
+ `function c *\\(e, *f\\) *{ *} *` +
|
|
|
|
+ `function d *\\(e, *f\\) *{ *} *` +
|
|
|
|
+ `}` +
|
|
|
|
+ ``);
|
|
|
|
+
|
|
|
|
+ let obfuscatedCode: string;
|
|
|
|
+
|
|
|
|
+ before(() => {
|
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-2.js');
|
|
|
|
+
|
|
|
|
+ obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
|
+ code,
|
|
|
|
+ {
|
|
|
|
+ ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
|
+ identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator
|
|
|
|
+ }
|
|
|
|
+ ).getObfuscatedCode();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it('Match #1: should generate valid identifier names', () => {
|
|
|
|
+ assert.match(obfuscatedCode, regExp);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ describe('Variant #2: `renameGlobals` option is enabled', () => {
|
|
|
|
+ const regExp: RegExp = new RegExp(`` +
|
|
|
|
+ `var a *= *'abc'; *` +
|
|
|
|
+ `function b *\\(d, *e\\) *{` +
|
|
|
|
+ `function f *\\(h, *i\\) *{ *} *` +
|
|
|
|
+ `function g *\\(h, *i\\) *{ *} *` +
|
|
|
|
+ `} *` +
|
|
|
|
+ `function c *\\(d, *e\\) *{` +
|
|
|
|
+ `function f *\\(h, *i\\) *{ *} *` +
|
|
|
|
+ `function g *\\(h, *i\\) *{ *} *` +
|
|
|
|
+ `}` +
|
|
|
|
+ ``);
|
|
|
|
+
|
|
|
|
+ let obfuscatedCode: string;
|
|
|
|
+
|
|
|
|
+ before(() => {
|
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-2.js');
|
|
|
|
+
|
|
|
|
+ obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
|
+ code,
|
|
|
|
+ {
|
|
|
|
+ ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
|
+ identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
|
|
|
|
+ renameGlobals: true
|
|
|
|
+ }
|
|
|
|
+ ).getObfuscatedCode();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it('Match #1: should generate valid identifier names', () => {
|
|
|
|
+ assert.match(obfuscatedCode, regExp);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ });
|
|
});
|
|
});
|
|
});
|
|
});
|