ControlFlowStorageCallNode.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { injectable, inject } from 'inversify';
  2. import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
  3. import { Expression } from 'estree';
  4. import { TStatement } from '../../../types/node/TStatement';
  5. import { IOptions } from '../../../interfaces/options/IOptions';
  6. import { initializable } from '../../../decorators/Initializable';
  7. import { AbstractCustomNode } from '../../AbstractCustomNode';
  8. import { Nodes } from '../../../node/Nodes';
  9. @injectable()
  10. export class ControlFlowStorageCallNode extends AbstractCustomNode {
  11. /**
  12. * @type {string}
  13. */
  14. @initializable()
  15. private controlFlowStorageKey: string;
  16. /**
  17. * @type {string}
  18. */
  19. @initializable()
  20. private controlFlowStorageName: string;
  21. /**
  22. * @type {Expression}
  23. */
  24. @initializable()
  25. private leftValue: Expression;
  26. /**
  27. * @type {ESTree.Expression}
  28. */
  29. @initializable()
  30. private rightValue: Expression;
  31. /**
  32. * @param options
  33. */
  34. constructor (
  35. @inject(ServiceIdentifiers.IOptions) options: IOptions
  36. ) {
  37. super(options);
  38. }
  39. /**
  40. * @param controlFlowStorageName
  41. * @param controlFlowStorageKey
  42. * @param leftValue
  43. * @param rightValue
  44. */
  45. public initialize (
  46. controlFlowStorageName: string,
  47. controlFlowStorageKey: string,
  48. leftValue: Expression,
  49. rightValue: Expression,
  50. ): void {
  51. this.controlFlowStorageName = controlFlowStorageName;
  52. this.controlFlowStorageKey = controlFlowStorageKey;
  53. this.leftValue = leftValue;
  54. this.rightValue = rightValue;
  55. }
  56. protected getNodeStructure (): TStatement[] {
  57. return [
  58. Nodes.getExpressionStatementNode(
  59. Nodes.getCallExpressionNode(
  60. Nodes.getMemberExpressionNode(
  61. Nodes.getIdentifierNode(this.controlFlowStorageName),
  62. Nodes.getIdentifierNode(this.controlFlowStorageKey)
  63. ),
  64. [
  65. this.leftValue,
  66. this.rightValue
  67. ]
  68. )
  69. )
  70. ];
  71. }
  72. }