DebugProtectionFunctionIntervalNode.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import * as ESTree from 'estree';
  2. import 'format-unicorn';
  3. import { IOptions } from "../../interfaces/IOptions";
  4. import { TNodeWithBlockStatement } from "../../types/TNodeWithBlockStatement";
  5. import { AppendState } from "../../enums/AppendState";
  6. import { DebugProtectionFunctionIntervalTemplate } from "../../templates/custom-nodes/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate";
  7. import { AbstractCustomNode } from '../AbstractCustomNode';
  8. import { NodeUtils } from '../../NodeUtils';
  9. export class DebugProtectionFunctionIntervalNode extends AbstractCustomNode {
  10. /**
  11. * @type {AppendState}
  12. */
  13. protected appendState: AppendState = AppendState.BeforeObfuscation;
  14. /**
  15. * @type {string}
  16. */
  17. private debugProtectionFunctionName: string;
  18. /**
  19. * @param debugProtectionFunctionName
  20. * @param options
  21. */
  22. constructor (debugProtectionFunctionName: string, options: IOptions) {
  23. super(options);
  24. this.debugProtectionFunctionName = debugProtectionFunctionName;
  25. }
  26. /**
  27. * @param blockScopeNode
  28. */
  29. public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
  30. NodeUtils.appendNode(blockScopeNode.body, this.getNode());
  31. }
  32. /**
  33. * @returns {ESTree.Node}
  34. */
  35. protected getNodeStructure (): ESTree.Node {
  36. return NodeUtils.convertCodeToStructure(
  37. DebugProtectionFunctionIntervalTemplate().formatUnicorn({
  38. debugProtectionFunctionName: this.debugProtectionFunctionName
  39. })
  40. );
  41. }
  42. }