123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import * as estraverse from 'estraverse';
- import { ITreeNode } from '../interfaces/nodes/ITreeNode';
- import { NodeType } from '../enums/NodeType';
- import { Node } from './Node';
- import { NodeUtils } from '../NodeUtils';
- export class DebugProtectionFunctionIntervalNode extends Node {
- /**
- * @type {ITreeNode}
- */
- protected node: ITreeNode;
- /**
- * @type {ITreeNode}
- */
- private astTree: ITreeNode;
- /**
- * @type {string}
- */
- private debugProtectionFunctionName: string;
- /**
- * @param astTree
- * @param debugProtectionFunctionName
- */
- constructor (
- astTree: ITreeNode,
- debugProtectionFunctionName: string
- ) {
- super();
- this.astTree = astTree;
- this.debugProtectionFunctionName = debugProtectionFunctionName;
- this.node = this.getNodeStructure();
- }
- public appendNode (): void {
- estraverse.replace(this.astTree, {
- leave: (node: ITreeNode, parent: ITreeNode): any => {
- if (NodeUtils.isProgramNode(node)) {
- node.body.push(this.getNode());
- return estraverse.VisitorOption.Break;
- }
- return estraverse.VisitorOption.Skip;
- }
- });
- }
- /**
- * @returns any
- */
- protected getNodeStructure (): any {
- return {
- 'type': NodeType.ExpressionStatement,
- 'expression': {
- 'type': NodeType.CallExpression,
- 'callee': {
- 'type': NodeType.Identifier,
- 'name': 'setInterval'
- },
- 'arguments': [
- {
- 'type': NodeType.FunctionExpression,
- 'id': null,
- 'params': [],
- 'defaults': [],
- 'body': {
- 'type': NodeType.BlockStatement,
- 'body': [
- {
- 'type': NodeType.ExpressionStatement,
- 'expression': {
- 'type': NodeType.CallExpression,
- 'callee': {
- 'type': NodeType.Identifier,
- 'name': this.debugProtectionFunctionName
- },
- 'arguments': []
- }
- }
- ]
- },
- 'generator': false,
- 'expression': false
- },
- {
- 'type': NodeType.Literal,
- 'value': 4000,
- 'raw': '4000'
- }
- ]
- }
- };
- }
- }
|