1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import { injectable, inject } from 'inversify';
- import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
- import * as ESTree from 'estree';
- import { TControlFlowCustomNodeFactory } from '../../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
- import { TStatement } from '../../../types/node/TStatement';
- import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
- import { IOptions } from '../../../interfaces/options/IOptions';
- import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
- import { ControlFlowCustomNode } from '../../../enums/container/custom-nodes/ControlFlowCustomNode';
- import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer';
- import { Node } from '../../../node/Node';
- @injectable()
- export abstract class ExpressionWithOperatorControlFlowReplacer extends AbstractControlFlowReplacer {
- /**
- * @type {IOptions}
- */
- protected readonly options: IOptions;
- /**
- * @type {Map<string, Map<string, string[]>>}
- */
- protected readonly replacerDataByControlFlowStorageId: Map <string, Map<string, string[]>> = new Map();
- /**
- * @param {TControlFlowCustomNodeFactory} controlFlowCustomNodeFactory
- * @param {IRandomGenerator} randomGenerator
- * @param {IOptions} options
- */
- constructor (
- @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode)
- controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory,
- @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
- @inject(ServiceIdentifiers.IOptions) options: IOptions
- ) {
- super(controlFlowCustomNodeFactory, randomGenerator, options);
- }
- /**
- * @param {string} controlFlowStorageId
- * @param {string} storageKey
- * @param {Expression} leftExpression
- * @param {Expression} rightExpression
- * @returns {Node}
- */
- protected getControlFlowStorageCallNode (
- controlFlowStorageId: string,
- storageKey: string,
- leftExpression: ESTree.Expression,
- rightExpression: ESTree.Expression
- ): ESTree.Node {
- const controlFlowStorageCallCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
- ControlFlowCustomNode.ExpressionWithOperatorControlFlowStorageCallNode
- );
- controlFlowStorageCallCustomNode.initialize(controlFlowStorageId, storageKey, leftExpression, rightExpression);
- const statementNode: TStatement = controlFlowStorageCallCustomNode.getNode()[0];
- if (!statementNode || !Node.isExpressionStatementNode(statementNode)) {
- throw new Error(`\`controlFlowStorageCallCustomNode.getNode()[0]\` should returns array with \`ExpressionStatement\` node`);
- }
- return statementNode.expression;
- }
- }
|