forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParentificationTransformer.ts
More file actions
48 lines (42 loc) · 1.44 KB
/
Copy pathParentificationTransformer.ts
File metadata and controls
48 lines (42 loc) · 1.44 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
import { inject, injectable, } from 'inversify';
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
import * as ESTree from 'estree';
import { IOptions } from '../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { NodeUtils } from '../../node/NodeUtils';
/**
* Adds `parentNode` properties to each node
*/
@injectable()
export class ParentificationTransformer extends AbstractNodeTransformer {
/**
* @param {IRandomGenerator} randomGenerator
* @param {IOptions} options
*/
constructor (
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
@inject(ServiceIdentifiers.IOptions) options: IOptions
) {
super(randomGenerator, options);
}
/**
* @return {IVisitor}
*/
public getVisitor (): IVisitor {
return {
enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
return this.transformNode(node, parentNode);
}
};
}
/**
* @param {Node} node
* @param {Node} parentNode
* @returns {Node}
*/
public transformNode (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node {
return NodeUtils.parentizeNode(node, parentNode);
}
}