dev.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. import { TIdentifierNamesCache } from '../../src/types/caches/TIdentifierNamesCache';
  3. import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
  4. (function () {
  5. const JavaScriptObfuscator: any = require('../../index');
  6. const existingIdentifierNamesCache: TIdentifierNamesCache | null = {
  7. foo: 'foo_existing',
  8. bar: 'bar_existing'
  9. };
  10. let obfuscationResult = JavaScriptObfuscator.obfuscate(
  11. `
  12. (() => {
  13. function foo(a, b, c, d) {
  14. console.log(a, b, c, d)
  15. }
  16. function bar(...args) {
  17. foo(...args, 5)
  18. }
  19. bar(...[1, 2, 3], 4)
  20. })();
  21. `,
  22. {
  23. ...NO_ADDITIONAL_NODES_PRESET,
  24. compact: false,
  25. identifierNamesCache: existingIdentifierNamesCache,
  26. identifierNamesGenerator: 'mangled-shuffled'
  27. }
  28. );
  29. let obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
  30. let identifierNamesCache = obfuscationResult.getIdentifierNamesCache();
  31. console.log(obfuscatedCode);
  32. console.log(eval(obfuscatedCode));
  33. console.log(identifierNamesCache);
  34. })();