StringLiteralNode.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 { IOptions } from '../../interfaces/options/IOptions';
  6. import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
  7. import { initializable } from '../../decorators/Initializable';
  8. import { AbstractCustomNode } from '../AbstractCustomNode';
  9. import { NodeFactory } from '../../node/NodeFactory';
  10. @injectable()
  11. export class StringLiteralNode extends AbstractCustomNode {
  12. /**
  13. * @type {string}
  14. */
  15. @initializable()
  16. private literalValue!: string;
  17. /**
  18. * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
  19. * @param {IRandomGenerator} randomGenerator
  20. * @param {IOptions} options
  21. */
  22. constructor (
  23. @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
  24. identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
  25. @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
  26. @inject(ServiceIdentifiers.IOptions) options: IOptions
  27. ) {
  28. super(identifierNamesGeneratorFactory, randomGenerator, options);
  29. }
  30. /**
  31. * @param {string} literalValue
  32. */
  33. public initialize (literalValue: string): void {
  34. this.literalValue = literalValue;
  35. }
  36. /**
  37. * @returns {TStatement[]}
  38. */
  39. protected getNodeStructure (): TStatement[] {
  40. const structure: TStatement = NodeFactory.expressionStatementNode(
  41. NodeFactory.literalNode(this.literalValue)
  42. );
  43. return [structure];
  44. }
  45. }