ExpressionWithOperatorControlFlowStorageCallNode.ts 2.9 KB

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