ScopeAnalyzer.spec.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import 'reflect-metadata';
  2. import { assert } from 'chai';
  3. import { readFileAsString } from '../../../helpers/readFileAsString';
  4. import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
  5. describe('ScopeAnalyzer', () => {
  6. describe('analyze', () => {
  7. /**
  8. * https://github.com/javascript-obfuscator/javascript-obfuscator/issues/804
  9. */
  10. describe('Variant #1: should attach a valid missing ranges', function() {
  11. this.timeout(120000);
  12. const samplesCount: number = 1000;
  13. let error: string | null = null;
  14. beforeEach(() => {
  15. const code: string = readFileAsString(__dirname + '/fixtures/attach-missing-ranges.js');
  16. for (let i = 0; i < samplesCount; i++) {
  17. let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
  18. code,
  19. {
  20. stringArray: false,
  21. selfDefending: true,
  22. controlFlowFlattening: true,
  23. controlFlowFlatteningThreshold: 0.1,
  24. splitStrings: false,
  25. seed: i
  26. }
  27. ).getObfuscatedCode();
  28. try {
  29. eval(obfuscatedCode);
  30. } catch ({message}) {
  31. error = message;
  32. break;
  33. }
  34. }
  35. });
  36. it('should attach missing ranges based on the parent node and rename identifiers without errors', () => {
  37. assert.equal(error, null);
  38. });
  39. });
  40. });
  41. });