1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import { injectable, inject } from 'inversify';
- import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
- import * as ESTree from 'estree';
- import { Expression } from 'estree';
- import { TStatement } from '../../../types/node/TStatement';
- import { IOptions } from '../../../interfaces/options/IOptions';
- import { IRandomGenerator } from "../../../interfaces/utils/IRandomGenerator";
- import { initializable } from '../../../decorators/Initializable';
- import { AbstractCustomNode } from '../../AbstractCustomNode';
- import { Nodes } from '../../../node/Nodes';
- import { NodeUtils } from '../../../node/NodeUtils';
- @injectable()
- export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode {
- /**
- * @type {Expression}
- */
- @initializable()
- private callee: Expression;
- /**
- * @type {string}
- */
- @initializable()
- private controlFlowStorageKey: string;
- /**
- * @type {string}
- */
- @initializable()
- private controlFlowStorageName: string;
- /**
- * @type {(ESTree.Expression | ESTree.SpreadElement)[]}
- */
- @initializable()
- private expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[];
- /**
- * @type {IRandomGenerator}
- */
- private readonly randomGenerator: IRandomGenerator;
- /**
- * @param randomGenerator
- * @param options
- */
- constructor (
- @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
- @inject(ServiceIdentifiers.IOptions) options: IOptions
- ) {
- super(options);
- this.randomGenerator = randomGenerator;
- }
- /**
- * @param controlFlowStorageName
- * @param controlFlowStorageKey
- * @param callee
- * @param expressionArguments
- */
- public initialize (
- controlFlowStorageName: string,
- controlFlowStorageKey: string,
- callee: Expression,
- expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[]
- ): void {
- this.controlFlowStorageName = controlFlowStorageName;
- this.controlFlowStorageKey = controlFlowStorageKey;
- this.callee = callee;
- this.expressionArguments = expressionArguments;
- }
- protected getNodeStructure (): TStatement[] {
- const structure: TStatement = Nodes.getExpressionStatementNode(
- Nodes.getCallExpressionNode(
- Nodes.getMemberExpressionNode(
- Nodes.getIdentifierNode(this.controlFlowStorageName),
- Nodes.getIdentifierNode(this.controlFlowStorageKey)
- ),
- [
- this.callee,
- ...this.expressionArguments
- ]
- )
- );
- NodeUtils.parentize(structure);
- return [structure];
- }
- }
|