ControlFlowStorageCallNode.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import * as format from 'string-template';
  2. import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
  3. import { IOptions } from '../../../interfaces/IOptions';
  4. import { AppendState } from '../../../enums/AppendState';
  5. import { ControlFlowStorageCallTemplate } from '../../../templates/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/ControlFlowStorageCallTemplate';
  6. import { AbstractCustomNode } from '../../AbstractCustomNode';
  7. import { NodeAppender } from '../../../node/NodeAppender';
  8. export class ControlFlowStorageCallNode extends AbstractCustomNode {
  9. /**
  10. * @type {AppendState}
  11. */
  12. protected appendState: AppendState = AppendState.AfterObfuscation;
  13. /**
  14. * @type {string}
  15. */
  16. private controlFlowStorageKey: string;
  17. /**
  18. * @type {string}
  19. */
  20. private controlFlowStorageName: string;
  21. /**
  22. * @type {string}
  23. */
  24. private leftValue: string;
  25. /**
  26. * @type {string}
  27. */
  28. private rightValue: string;
  29. /**
  30. * @param controlFlowStorageName
  31. * @param controlFlowStorageKey
  32. * @param leftValue
  33. * @param rightValue
  34. * @param options
  35. */
  36. constructor (
  37. controlFlowStorageName: string,
  38. controlFlowStorageKey: string,
  39. leftValue: string,
  40. rightValue: string,
  41. options: IOptions
  42. ) {
  43. super(options);
  44. this.controlFlowStorageName = controlFlowStorageName;
  45. this.controlFlowStorageKey = controlFlowStorageKey;
  46. this.leftValue = leftValue;
  47. this.rightValue = rightValue;
  48. }
  49. /**
  50. * @param blockScopeNode
  51. */
  52. public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
  53. NodeAppender.prependNode(blockScopeNode, this.getNode());
  54. }
  55. /**
  56. * @returns {string}
  57. */
  58. public getCode (): string {
  59. return format(ControlFlowStorageCallTemplate(), {
  60. controlFlowStorageKey: this.controlFlowStorageKey,
  61. controlFlowStorageName: this.controlFlowStorageName,
  62. leftValue: this.leftValue,
  63. rightValue: this.rightValue
  64. });
  65. }
  66. }