mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Switched from escodegen to escodegen-wallaby
This commit is contained in:
@@ -40,6 +40,41 @@ export class NodeUtils {
|
||||
return astTree;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param astTree
|
||||
* @return {ESTree.Node}
|
||||
*/
|
||||
public static clone <T extends ESTree.Node> (astTree: T): T {
|
||||
const cloneRecursive: (node: T) => T = (node: T) => {
|
||||
const copy: {[key: string]: any} = {};
|
||||
|
||||
Object
|
||||
.keys(node)
|
||||
.filter((property: string) => property !== 'parentNode')
|
||||
.forEach((property: string): void => {
|
||||
const value: any = (<{[key: string]: any}>node)[property];
|
||||
|
||||
let clonedValue: any | null;
|
||||
|
||||
if (value === null || value instanceof RegExp) {
|
||||
clonedValue = value;
|
||||
} else if (Array.isArray(value)) {
|
||||
clonedValue = value.map(cloneRecursive);
|
||||
} else if (typeof value === 'object') {
|
||||
clonedValue = cloneRecursive(value);
|
||||
} else {
|
||||
clonedValue = value;
|
||||
}
|
||||
|
||||
copy[property] = clonedValue;
|
||||
});
|
||||
|
||||
return <T>copy;
|
||||
};
|
||||
|
||||
return NodeUtils.parentize(cloneRecursive(astTree));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param code
|
||||
* @returns {TStatement[]}
|
||||
|
||||
+7
-1
@@ -189,13 +189,19 @@ export class Nodes {
|
||||
/**
|
||||
* @param test
|
||||
* @param consequent
|
||||
* @param alternate
|
||||
* @returns {ESTree.IfStatement}
|
||||
*/
|
||||
public static getIfStatementNode (test: ESTree.Expression, consequent: ESTree.BlockStatement): ESTree.IfStatement {
|
||||
public static getIfStatementNode (
|
||||
test: ESTree.Expression,
|
||||
consequent: ESTree.BlockStatement,
|
||||
alternate?: ESTree.BlockStatement
|
||||
): ESTree.IfStatement {
|
||||
return {
|
||||
type: NodeType.IfStatement,
|
||||
test,
|
||||
consequent,
|
||||
...alternate && {alternate},
|
||||
obfuscatedNode: false
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user