Fixed string array name preserving inside string array helpers

This commit is contained in:
sanex3339
2020-02-16 23:39:39 +03:00
parent a2e9c05ce8
commit 499c2b1a33
14 changed files with 176 additions and 57 deletions
@@ -1,5 +1,8 @@
import { assert } from 'chai';
import { IdentifierNamesGenerator } from '../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
import { StringArrayEncoding } from '../../../../src/enums/StringArrayEncoding';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../helpers/readFileAsString';
@@ -49,4 +52,33 @@ describe('StringArrayCallsWrapperCodeHelper', () => {
assert.notMatch(obfuscatedCode, regExp);
});
});
describe('Preserve string array name', () => {
const callsWrapperRegExp: RegExp = new RegExp(`` +
`var b *= *function *\\(c, *d\\) *{ *` +
`c *= *c *- *0x0; *` +
`var e *= *a\\[c]; *` +
``);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
stringArray: true,
stringArrayThreshold: 1,
stringArrayEncoding: StringArrayEncoding.Base64
}
).getObfuscatedCode();
});
it('should preserve string array name', () => {
assert.match(obfuscatedCode, callsWrapperRegExp);
});
});
});