import { injectable, inject } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as format from 'string-template'; import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; import { IOptions } from '../../interfaces/options/IOptions'; import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; import { initializable } from '../../decorators/Initializable'; import { DebugProtectionFunctionIntervalTemplate } from '../../templates/custom-nodes/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { NodeAppender } from '../../node/NodeAppender'; @injectable() export class DebugProtectionFunctionIntervalNode extends AbstractCustomNode { /** * @type {TObfuscationEvent} */ protected readonly appendEvent: TObfuscationEvent = ObfuscationEvents.BeforeObfuscation; /** * @type {string} */ @initializable() private debugProtectionFunctionName: string; /** * @param options */ constructor ( @inject(ServiceIdentifiers.IOptions) options: IOptions ) { super(options); } /** * @param debugProtectionFunctionName */ public initialize (debugProtectionFunctionName: string): void { this.debugProtectionFunctionName = debugProtectionFunctionName; } /** * @param blockScopeNode * @param stackTraceData */ public appendNode (blockScopeNode: TNodeWithBlockStatement, stackTraceData: IStackTraceData[]): void { NodeAppender.appendNode(blockScopeNode, this.getNode()); } /** * @returns {string} */ public getCode (): string { return format(DebugProtectionFunctionIntervalTemplate(), { debugProtectionFunctionName: this.debugProtectionFunctionName }); } }