Fixed incorrect rename of the identifiers of the added helpers in some rare cases

Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/804
This commit is contained in:
sanex
2020-11-10 01:05:21 +03:00
parent f28445f230
commit 8e55d19ebb
10 changed files with 78 additions and 20 deletions
@@ -0,0 +1,50 @@
import 'reflect-metadata';
import { assert } from 'chai';
import { readFileAsString } from '../../../helpers/readFileAsString';
import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
describe('ScopeAnalyzer', () => {
describe('analyze', () => {
/**
* https://github.com/javascript-obfuscator/javascript-obfuscator/issues/804
*/
describe('Variant #1: should attach a valid missing ranges', function() {
this.timeout(120000);
const samplesCount: number = 1000;
let error: string | null = null;
beforeEach(() => {
const code: string = readFileAsString(__dirname + '/fixtures/attach-missing-ranges.js');
for (let i = 0; i < samplesCount; i++) {
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
code,
{
stringArray: false,
selfDefending: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.1,
splitStrings: false,
seed: i
}
).getObfuscatedCode();
try {
eval(obfuscatedCode);
} catch ({message}) {
error = message;
break;
}
}
});
it('should attach missing ranges based on the parent node and rename identifiers without errors', () => {
assert.equal(error, null);
});
});
});
});
@@ -0,0 +1,3 @@
function foo () {}
foo();
+1
View File
@@ -51,6 +51,7 @@ import './unit-tests/utils/Utils.spec';
* Functional tests
*/
import './functional-tests/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.spec';
import './functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec';
import './functional-tests/cli/JavaScriptObfuscatorCLI.spec';
import './functional-tests/code-transformers/preparing-transformers/hashbang-operator-transformer/HashbangOperatorTransformer.spec';
import './functional-tests/custom-code-helpers/common/templates/GlobalVariableNoEvalTemplate.spec';