ConsoleOutputDisableExpressionNode.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import * as format from 'string-template';
  2. import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
  3. import { IOptions } from '../../interfaces/IOptions';
  4. import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData';
  5. import { AppendState } from '../../enums/AppendState';
  6. import { ConsoleOutputDisableExpressionTemplate } from '../../templates/custom-nodes/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate';
  7. import { AbstractCustomNode } from '../AbstractCustomNode';
  8. import { NodeAppender } from '../../node/NodeAppender';
  9. import { Utils } from '../../Utils';
  10. export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
  11. /**
  12. * @type {AppendState}
  13. */
  14. protected appendState: AppendState = AppendState.BeforeObfuscation;
  15. /**
  16. * @type {string}
  17. */
  18. protected callsControllerFunctionName: string;
  19. /**
  20. * @type {number}
  21. */
  22. protected randomStackTraceIndex: number;
  23. /**
  24. * @type {IStackTraceData[]}
  25. */
  26. protected stackTraceData: IStackTraceData[];
  27. /**
  28. * @param stackTraceData
  29. * @param callsControllerFunctionName
  30. * @param randomStackTraceIndex
  31. * @param options
  32. */
  33. constructor (
  34. stackTraceData: IStackTraceData[],
  35. callsControllerFunctionName: string,
  36. randomStackTraceIndex: number,
  37. options: IOptions
  38. ) {
  39. super(options);
  40. this.stackTraceData = stackTraceData;
  41. this.callsControllerFunctionName = callsControllerFunctionName;
  42. this.randomStackTraceIndex = randomStackTraceIndex;
  43. }
  44. /**
  45. * @param blockScopeNode
  46. */
  47. public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
  48. NodeAppender.appendNodeToOptimalBlockScope(
  49. this.stackTraceData,
  50. blockScopeNode,
  51. this.getNode(),
  52. this.randomStackTraceIndex
  53. );
  54. }
  55. /**
  56. * @returns {string}
  57. */
  58. public getCode (): string {
  59. return format(ConsoleOutputDisableExpressionTemplate(), {
  60. consoleLogDisableFunctionName: Utils.getRandomVariableName(),
  61. singleNodeCallControllerFunctionName: this.callsControllerFunctionName
  62. });
  63. }
  64. }