forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractNodeTransformer.ts
More file actions
61 lines (51 loc) · 1.8 KB
/
Copy pathAbstractNodeTransformer.ts
File metadata and controls
61 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { inject, injectable, postConstruct } from 'inversify';
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
import * as estraverse from 'estraverse';
import * as ESTree from 'estree';
import { IInitializable } from '../interfaces/IInitializable';
import { INodeTransformer } from '../interfaces/node-transformers/INodeTransformer';
import { IOptions } from '../interfaces/options/IOptions';
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
import { IVisitor } from '../interfaces/node-transformers/IVisitor';
import { initializable } from '../decorators/Initializable';
@injectable()
export abstract class AbstractNodeTransformer implements INodeTransformer, IInitializable {
/**
* @type {number}
*/
@initializable()
protected nodeIdentifier: number;
/**
* @type {IOptions}
*/
protected readonly options: IOptions;
/**
* @type {IRandomGenerator}
*/
protected readonly randomGenerator: IRandomGenerator;
/**
* @param {IRandomGenerator} randomGenerator
* @param {IOptions} options
*/
constructor (
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
@inject(ServiceIdentifiers.IOptions) options: IOptions
) {
this.randomGenerator = randomGenerator;
this.options = options;
}
@postConstruct()
public initialize (): void {
this.nodeIdentifier = this.randomGenerator.getRandomInteger(0, 10000);
}
/**
* @returns {IVisitor}
*/
public abstract getVisitor (): IVisitor;
/**
* @param {Node} node
* @param {Node} parentNode
* @returns {Node | VisitorOption}
*/
public abstract transformNode (node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node | estraverse.VisitorOption;
}