StringLiteralControlFlowStorageCallNode.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { inject, injectable, } from 'inversify';
  2. import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
  3. import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
  4. import { TStatement } from '../../../types/node/TStatement';
  5. import { ICustomCodeHelperFormatter } from '../../../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
  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 { NodeFactory } from '../../../node/NodeFactory';
  11. import { NodeUtils } from '../../../node/NodeUtils';
  12. @injectable()
  13. export class StringLiteralControlFlowStorageCallNode 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. * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
  26. * @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
  27. * @param {IRandomGenerator} randomGenerator
  28. * @param {IOptions} options
  29. */
  30. public constructor (
  31. @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
  32. identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
  33. @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter,
  34. @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
  35. @inject(ServiceIdentifiers.IOptions) options: IOptions
  36. ) {
  37. super(
  38. identifierNamesGeneratorFactory,
  39. customCodeHelperFormatter,
  40. randomGenerator,
  41. options
  42. );
  43. }
  44. /**
  45. * @param {string} controlFlowStorageName
  46. * @param {string} controlFlowStorageKey
  47. */
  48. public initialize (
  49. controlFlowStorageName: string,
  50. controlFlowStorageKey: string
  51. ): void {
  52. this.controlFlowStorageName = controlFlowStorageName;
  53. this.controlFlowStorageKey = controlFlowStorageKey;
  54. }
  55. /**
  56. * @returns {TStatement[]}
  57. */
  58. protected getNodeStructure (): TStatement[] {
  59. const structure: TStatement = NodeFactory.expressionStatementNode(
  60. NodeFactory.memberExpressionNode(
  61. NodeFactory.identifierNode(this.controlFlowStorageName),
  62. NodeFactory.identifierNode(this.controlFlowStorageKey)
  63. )
  64. );
  65. NodeUtils.parentizeAst(structure);
  66. return [structure];
  67. }
  68. }