mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
refactoring
This commit is contained in:
+3
-12
@@ -16,6 +16,9 @@ class NodeUtils {
|
||||
return node;
|
||||
}
|
||||
static getBlockScopeOfNode(node, depth = 0) {
|
||||
if (!node.parentNode) {
|
||||
throw new ReferenceError('`parentNode` property of given node is `undefined`');
|
||||
}
|
||||
if (node.parentNode.type === NodeType_1.NodeType.Program) {
|
||||
return node.parentNode;
|
||||
}
|
||||
@@ -30,18 +33,6 @@ class NodeUtils {
|
||||
}
|
||||
return node;
|
||||
}
|
||||
static getParentNodeWithType(node, types, limitNodeTypes = [], depth = 0) {
|
||||
if (node.parentNode.type === NodeType_1.NodeType.Program || Utils_1.Utils.arrayContains(limitNodeTypes, node.parentNode.type)) {
|
||||
return node.parentNode;
|
||||
}
|
||||
if (!Utils_1.Utils.arrayContains(types, node.parentNode.type)) {
|
||||
return NodeUtils.getParentNodeWithType(node.parentNode, types, limitNodeTypes, depth);
|
||||
}
|
||||
if (depth > 0) {
|
||||
return NodeUtils.getParentNodeWithType(node.parentNode, types, limitNodeTypes, --depth);
|
||||
}
|
||||
return node.parentNode;
|
||||
}
|
||||
static insertNodeAtIndex(blockScopeBody, node, index) {
|
||||
if (!NodeUtils.validateNode(node)) {
|
||||
return;
|
||||
|
||||
+4
-28
@@ -57,6 +57,10 @@ export class NodeUtils {
|
||||
* @returns {INode}
|
||||
*/
|
||||
public static getBlockScopeOfNode (node: INode, depth: number = 0): BlockScopeNode {
|
||||
if (!node.parentNode) {
|
||||
throw new ReferenceError('`parentNode` property of given node is `undefined`');
|
||||
}
|
||||
|
||||
if (node.parentNode.type === NodeType.Program) {
|
||||
return <BlockScopeNode> node.parentNode;
|
||||
}
|
||||
@@ -76,34 +80,6 @@ export class NodeUtils {
|
||||
return <BlockScopeNode> node; // blocks statement of scopeNodes
|
||||
}
|
||||
|
||||
/**
|
||||
* @param node
|
||||
* @param types
|
||||
* @param limitNodeTypes
|
||||
* @param depth
|
||||
* @returns {INode}
|
||||
*/
|
||||
public static getParentNodeWithType (
|
||||
node: INode,
|
||||
types: string[],
|
||||
limitNodeTypes: string[] = [],
|
||||
depth: number = 0
|
||||
): INode {
|
||||
if (node.parentNode.type === NodeType.Program || Utils.arrayContains(limitNodeTypes, node.parentNode.type)) {
|
||||
return node.parentNode;
|
||||
}
|
||||
|
||||
if (!Utils.arrayContains(types, node.parentNode.type)) {
|
||||
return NodeUtils.getParentNodeWithType(node.parentNode, types, limitNodeTypes, depth);
|
||||
}
|
||||
|
||||
if (depth > 0) {
|
||||
return NodeUtils.getParentNodeWithType(node.parentNode, types, limitNodeTypes, --depth);
|
||||
}
|
||||
|
||||
return node.parentNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param blockScopeBody
|
||||
* @param node
|
||||
|
||||
Reference in New Issue
Block a user