UNPKG

anobis

Version:
68 lines (54 loc) 2.11 kB
import { injectable, inject } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as format from 'string-template'; import { TStatement } from '../../types/node/TStatement'; import { IOptions } from '../../interfaces/options/IOptions'; import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; import { ConsoleOutputDisableExpressionTemplate } from '../../templates/custom-nodes/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate'; import { initializable } from '../../decorators/Initializable'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { NodeUtils } from '../../node/NodeUtils'; @injectable() export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode { /** * @type {string} */ @initializable() private callsControllerFunctionName: string; /** * @type {IRandomGenerator} */ private readonly randomGenerator: IRandomGenerator; /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ constructor ( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { super(options); this.randomGenerator = randomGenerator; } /** * @param {string} callsControllerFunctionName */ public initialize (callsControllerFunctionName: string): void { this.callsControllerFunctionName = callsControllerFunctionName; } /** * @returns {TStatement[]} */ protected getNodeStructure (): TStatement[] { return NodeUtils.convertCodeToStructure(this.getTemplate()); } /** * @returns {string} */ protected getTemplate (): string { return format(ConsoleOutputDisableExpressionTemplate(), { consoleLogDisableFunctionName: this.randomGenerator.getRandomVariableName(6), singleNodeCallControllerFunctionName: this.callsControllerFunctionName }); } }