mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
refactoring
This commit is contained in:
+14
-13
@@ -1,8 +1,9 @@
|
||||
"use strict";
|
||||
const NodeType_1 = require("./enums/NodeType");
|
||||
const Utils_1 = require("./Utils");
|
||||
class NodeUtils {
|
||||
static getScopeOfNode(node, depth = 0) {
|
||||
if (node.parentNode.type === 'Program') {
|
||||
if (node.parentNode.type === NodeType_1.NodeType.Program) {
|
||||
return node.parentNode;
|
||||
}
|
||||
if (!Utils_1.Utils.arrayContains(NodeUtils.scopeNodes, node.parentNode.type)) {
|
||||
@@ -11,13 +12,13 @@ class NodeUtils {
|
||||
if (depth > 0) {
|
||||
return NodeUtils.getScopeOfNode(node.parentNode, --depth);
|
||||
}
|
||||
if (node.type !== 'BlockStatement') {
|
||||
if (node.type !== NodeType_1.NodeType.BlockStatement) {
|
||||
return NodeUtils.getScopeOfNode(node.parentNode);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
static getParentNodeWithType(node, types, limitNodeTypes = [], depth = 0) {
|
||||
if (node.parentNode.type === 'Program' || Utils_1.Utils.arrayContains(limitNodeTypes, node.parentNode.type)) {
|
||||
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)) {
|
||||
@@ -29,28 +30,28 @@ class NodeUtils {
|
||||
return node.parentNode;
|
||||
}
|
||||
static isBlockStatementNode(node) {
|
||||
return node.type === 'BlockStatement';
|
||||
return node.type === NodeType_1.NodeType.BlockStatement;
|
||||
}
|
||||
static isIdentifierNode(node) {
|
||||
return node.type === 'Identifier';
|
||||
return node.type === NodeType_1.NodeType.Identifier;
|
||||
}
|
||||
static isLiteralNode(node) {
|
||||
return node.type === 'Literal';
|
||||
return node.type === NodeType_1.NodeType.Literal;
|
||||
}
|
||||
static isMemberExpressionNode(node) {
|
||||
return node.type === 'MemberExpression';
|
||||
return node.type === NodeType_1.NodeType.MemberExpression;
|
||||
}
|
||||
static isPropertyNode(node) {
|
||||
return node.type === 'Property';
|
||||
return node.type === NodeType_1.NodeType.Property;
|
||||
}
|
||||
static isVariableDeclaratorNode(node) {
|
||||
return node.type === 'VariableDeclarator';
|
||||
return node.type === NodeType_1.NodeType.VariableDeclarator;
|
||||
}
|
||||
}
|
||||
NodeUtils.scopeNodes = [
|
||||
'ArrowFunctionExpression',
|
||||
'FunctionDeclaration',
|
||||
'FunctionExpression',
|
||||
'MethodDefinition'
|
||||
NodeType_1.NodeType.ArrowFunctionExpression,
|
||||
NodeType_1.NodeType.FunctionDeclaration,
|
||||
NodeType_1.NodeType.FunctionExpression,
|
||||
NodeType_1.NodeType.MethodDefinition
|
||||
];
|
||||
exports.NodeUtils = NodeUtils;
|
||||
|
||||
+15
-13
@@ -6,6 +6,8 @@ import { IPropertyNode } from "./interfaces/nodes/IPropertyNode";
|
||||
import { ITreeNode } from './interfaces/nodes/ITreeNode';
|
||||
import { IVariableDeclaratorNode } from "./interfaces/nodes/IVariableDeclaratorNode";
|
||||
|
||||
import { NodeType } from "./enums/NodeType";
|
||||
|
||||
import { Utils } from "./Utils";
|
||||
|
||||
export class NodeUtils {
|
||||
@@ -13,10 +15,10 @@ export class NodeUtils {
|
||||
* @type {string[]}
|
||||
*/
|
||||
private static scopeNodes: string[] = [
|
||||
'ArrowFunctionExpression',
|
||||
'FunctionDeclaration',
|
||||
'FunctionExpression',
|
||||
'MethodDefinition'
|
||||
NodeType.ArrowFunctionExpression,
|
||||
NodeType.FunctionDeclaration,
|
||||
NodeType.FunctionExpression,
|
||||
NodeType.MethodDefinition
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -25,7 +27,7 @@ export class NodeUtils {
|
||||
* @returns {ITreeNode}
|
||||
*/
|
||||
public static getScopeOfNode (node: ITreeNode, depth: number = 0): ITreeNode {
|
||||
if (node.parentNode.type === 'Program') {
|
||||
if (node.parentNode.type === NodeType.Program) {
|
||||
return node.parentNode;
|
||||
}
|
||||
|
||||
@@ -37,7 +39,7 @@ export class NodeUtils {
|
||||
return NodeUtils.getScopeOfNode(node.parentNode, --depth);
|
||||
}
|
||||
|
||||
if (node.type !== 'BlockStatement') {
|
||||
if (node.type !== NodeType.BlockStatement) {
|
||||
return NodeUtils.getScopeOfNode(node.parentNode);
|
||||
}
|
||||
|
||||
@@ -57,7 +59,7 @@ export class NodeUtils {
|
||||
limitNodeTypes: string[] = [],
|
||||
depth: number = 0
|
||||
): ITreeNode {
|
||||
if (node.parentNode.type === 'Program' || Utils.arrayContains(limitNodeTypes, node.parentNode.type)) {
|
||||
if (node.parentNode.type === NodeType.Program || Utils.arrayContains(limitNodeTypes, node.parentNode.type)) {
|
||||
return node.parentNode;
|
||||
}
|
||||
|
||||
@@ -77,7 +79,7 @@ export class NodeUtils {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isBlockStatementNode (node: ITreeNode): node is IBlockStatementNode {
|
||||
return node.type === 'BlockStatement';
|
||||
return node.type === NodeType.BlockStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +87,7 @@ export class NodeUtils {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isIdentifierNode (node: ITreeNode): node is IIdentifierNode {
|
||||
return node.type === 'Identifier';
|
||||
return node.type === NodeType.Identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +95,7 @@ export class NodeUtils {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isLiteralNode (node: ITreeNode): node is ILiteralNode {
|
||||
return node.type === 'Literal';
|
||||
return node.type === NodeType.Literal;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +103,7 @@ export class NodeUtils {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isMemberExpressionNode (node: ITreeNode): node is IMemberExpressionNode {
|
||||
return node.type === 'MemberExpression';
|
||||
return node.type === NodeType.MemberExpression;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +113,7 @@ export class NodeUtils {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isPropertyNode (node: ITreeNode): node is IPropertyNode {
|
||||
return node.type === 'Property';
|
||||
return node.type === NodeType.Property;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,6 +122,6 @@ export class NodeUtils {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isVariableDeclaratorNode (node: ITreeNode): node is IVariableDeclaratorNode {
|
||||
return node.type === 'VariableDeclarator';
|
||||
return node.type === NodeType.VariableDeclarator;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-10
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
const estraverse = require('estraverse');
|
||||
const AppendState_1 = require('./enums/AppendState');
|
||||
const NodeType_1 = require("./enums/NodeType");
|
||||
const CatchClauseObfuscator_1 = require("./node-obfuscators/CatchClauseObfuscator");
|
||||
const FunctionDeclarationObfuscator_1 = require('./node-obfuscators/FunctionDeclarationObfuscator');
|
||||
const FunctionObfuscator_1 = require('./node-obfuscators/FunctionObfuscator');
|
||||
@@ -16,19 +17,19 @@ class Obfuscator {
|
||||
constructor(options = {}) {
|
||||
this.nodes = new Map();
|
||||
this.nodeObfuscators = new Map([
|
||||
['ClassDeclaration', [FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator]],
|
||||
['CatchClause', [CatchClauseObfuscator_1.CatchClauseObfuscator]],
|
||||
['FunctionDeclaration', [
|
||||
[NodeType_1.NodeType.ArrowFunctionExpression, [FunctionObfuscator_1.FunctionObfuscator]],
|
||||
[NodeType_1.NodeType.ClassDeclaration, [FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator]],
|
||||
[NodeType_1.NodeType.CatchClause, [CatchClauseObfuscator_1.CatchClauseObfuscator]],
|
||||
[NodeType_1.NodeType.FunctionDeclaration, [
|
||||
FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator,
|
||||
FunctionObfuscator_1.FunctionObfuscator
|
||||
]],
|
||||
['ArrowFunctionExpression', [FunctionObfuscator_1.FunctionObfuscator]],
|
||||
['FunctionExpression', [FunctionObfuscator_1.FunctionObfuscator]],
|
||||
['MethodDefinition', [MethodDefinitionObfuscator_1.MethodDefinitionObfuscator]],
|
||||
['VariableDeclaration', [VariableDeclarationObfuscator_1.VariableDeclarationObfuscator]],
|
||||
['ObjectExpression', [ObjectExpressionObfuscator_1.ObjectExpressionObfuscator]],
|
||||
['MemberExpression', [MemberExpressionObfuscator_1.MemberExpressionObfuscator]],
|
||||
['Literal', [LiteralObfuscator_1.LiteralObfuscator]]
|
||||
[NodeType_1.NodeType.FunctionExpression, [FunctionObfuscator_1.FunctionObfuscator]],
|
||||
[NodeType_1.NodeType.MemberExpression, [MemberExpressionObfuscator_1.MemberExpressionObfuscator]],
|
||||
[NodeType_1.NodeType.MethodDefinition, [MethodDefinitionObfuscator_1.MethodDefinitionObfuscator]],
|
||||
[NodeType_1.NodeType.ObjectExpression, [ObjectExpressionObfuscator_1.ObjectExpressionObfuscator]],
|
||||
[NodeType_1.NodeType.VariableDeclaration, [VariableDeclarationObfuscator_1.VariableDeclarationObfuscator]],
|
||||
[NodeType_1.NodeType.Literal, [LiteralObfuscator_1.LiteralObfuscator]]
|
||||
]);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
+11
-10
@@ -6,6 +6,7 @@ import { INodesGroup } from './interfaces/INodesGroup';
|
||||
import { ITreeNode } from './interfaces/nodes/ITreeNode';
|
||||
|
||||
import { AppendState } from './enums/AppendState';
|
||||
import { NodeType } from "./enums/NodeType";
|
||||
|
||||
import { CatchClauseObfuscator } from "./node-obfuscators/CatchClauseObfuscator";
|
||||
import { FunctionDeclarationObfuscator } from './node-obfuscators/FunctionDeclarationObfuscator';
|
||||
@@ -29,19 +30,19 @@ export class Obfuscator {
|
||||
* @type {Map<string, Function[]>}
|
||||
*/
|
||||
private nodeObfuscators: Map <string, Function[]> = new Map <string, Function[]> ([
|
||||
['ClassDeclaration', [FunctionDeclarationObfuscator]],
|
||||
['CatchClause', [CatchClauseObfuscator]],
|
||||
['FunctionDeclaration', [
|
||||
[NodeType.ArrowFunctionExpression, [FunctionObfuscator]],
|
||||
[NodeType.ClassDeclaration, [FunctionDeclarationObfuscator]],
|
||||
[NodeType.CatchClause, [CatchClauseObfuscator]],
|
||||
[NodeType.FunctionDeclaration, [
|
||||
FunctionDeclarationObfuscator,
|
||||
FunctionObfuscator
|
||||
]],
|
||||
['ArrowFunctionExpression', [FunctionObfuscator]],
|
||||
['FunctionExpression', [FunctionObfuscator]],
|
||||
['MethodDefinition', [MethodDefinitionObfuscator]],
|
||||
['VariableDeclaration', [VariableDeclarationObfuscator]],
|
||||
['ObjectExpression', [ObjectExpressionObfuscator]],
|
||||
['MemberExpression', [MemberExpressionObfuscator]],
|
||||
['Literal', [LiteralObfuscator]]
|
||||
[NodeType.FunctionExpression, [FunctionObfuscator]],
|
||||
[NodeType.MemberExpression, [MemberExpressionObfuscator]],
|
||||
[NodeType.MethodDefinition, [MethodDefinitionObfuscator]],
|
||||
[NodeType.ObjectExpression, [ObjectExpressionObfuscator]],
|
||||
[NodeType.VariableDeclaration, [VariableDeclarationObfuscator]],
|
||||
[NodeType.Literal, [LiteralObfuscator]]
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,9 @@ class Utils {
|
||||
const rangeMinInteger = 10000, rangeMaxInteger = 99999999, prefix = '_0x';
|
||||
return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger))).substr(0, length)}`;
|
||||
}
|
||||
static strEnumify(obj) {
|
||||
return obj;
|
||||
}
|
||||
static stringToUnicode(string) {
|
||||
return `'${string.replace(/[\s\S]/g, (escape) => {
|
||||
return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`;
|
||||
|
||||
@@ -64,6 +64,14 @@ export class Utils {
|
||||
return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger))).substr(0, length)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param obj
|
||||
* @returns {T}
|
||||
*/
|
||||
public static strEnumify <T extends { [prop: string]: '' | string }> (obj: T): T {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @returns {string}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
const Utils_1 = require("../Utils");
|
||||
exports.NodeType = Utils_1.Utils.strEnumify({
|
||||
ArrayExpression: 'ArrayExpression',
|
||||
ArrowFunctionExpression: 'ArrowFunctionExpression',
|
||||
AssignmentExpression: 'AssignmentExpression',
|
||||
BinaryExpression: 'BinaryExpression',
|
||||
BlockStatement: 'BlockStatement',
|
||||
CallExpression: 'CallExpression',
|
||||
CatchClause: 'CatchClause',
|
||||
ClassDeclaration: 'ClassDeclaration',
|
||||
ExpressionStatement: 'ExpressionStatement',
|
||||
FunctionDeclaration: 'FunctionDeclaration',
|
||||
FunctionExpression: 'FunctionExpression',
|
||||
Identifier: 'Identifier',
|
||||
IfStatement: 'IfStatement',
|
||||
Literal: 'Literal',
|
||||
LogicalExpression: 'LogicalExpression',
|
||||
MemberExpression: 'MemberExpression',
|
||||
MethodDefinition: 'MethodDefinition',
|
||||
ObjectExpression: 'ObjectExpression',
|
||||
Program: 'Program',
|
||||
Property: 'Property',
|
||||
ReturnStatement: 'ReturnStatement',
|
||||
UnaryExpression: 'UnaryExpression',
|
||||
UpdateExpression: 'UpdateExpression',
|
||||
VariableDeclaration: 'VariableDeclaration',
|
||||
VariableDeclarator: 'VariableDeclarator',
|
||||
WhileStatement: 'WhileStatement'
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Utils } from "../Utils";
|
||||
|
||||
export const NodeType: any = Utils.strEnumify({
|
||||
ArrayExpression: 'ArrayExpression',
|
||||
ArrowFunctionExpression: 'ArrowFunctionExpression',
|
||||
AssignmentExpression: 'AssignmentExpression',
|
||||
BinaryExpression: 'BinaryExpression',
|
||||
BlockStatement: 'BlockStatement',
|
||||
CallExpression: 'CallExpression',
|
||||
CatchClause: 'CatchClause',
|
||||
ClassDeclaration: 'ClassDeclaration',
|
||||
ExpressionStatement: 'ExpressionStatement',
|
||||
FunctionDeclaration: 'FunctionDeclaration',
|
||||
FunctionExpression: 'FunctionExpression',
|
||||
Identifier: 'Identifier',
|
||||
IfStatement: 'IfStatement',
|
||||
Literal: 'Literal',
|
||||
LogicalExpression: 'LogicalExpression',
|
||||
MemberExpression: 'MemberExpression',
|
||||
MethodDefinition: 'MethodDefinition',
|
||||
ObjectExpression: 'ObjectExpression',
|
||||
Program: 'Program',
|
||||
Property: 'Property',
|
||||
ReturnStatement: 'ReturnStatement',
|
||||
UnaryExpression: 'UnaryExpression',
|
||||
UpdateExpression: 'UpdateExpression',
|
||||
VariableDeclaration: 'VariableDeclaration',
|
||||
VariableDeclarator: 'VariableDeclarator',
|
||||
WhileStatement: 'WhileStatement'
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
const estraverse = require('estraverse');
|
||||
const NodeType_1 = require("../enums/NodeType");
|
||||
const NodeObfuscator_1 = require('./NodeObfuscator');
|
||||
const NodeUtils_1 = require("../NodeUtils");
|
||||
const Utils_1 = require('../Utils');
|
||||
@@ -9,7 +10,7 @@ class FunctionDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
|
||||
this.functionName = new Map();
|
||||
}
|
||||
obfuscateNode(functionDeclarationNode, parentNode) {
|
||||
if (parentNode.type === 'Program') {
|
||||
if (parentNode.type === NodeType_1.NodeType.Program) {
|
||||
return;
|
||||
}
|
||||
this.replaceFunctionName(functionDeclarationNode);
|
||||
|
||||
@@ -3,6 +3,8 @@ import * as estraverse from 'estraverse';
|
||||
import { IFunctionDeclarationNode } from "../interfaces/nodes/IFunctionDeclarationNode";
|
||||
import { ITreeNode } from "../interfaces/nodes/ITreeNode";
|
||||
|
||||
import { NodeType } from "../enums/NodeType";
|
||||
|
||||
import { NodeObfuscator } from './NodeObfuscator';
|
||||
import { NodeUtils } from "../NodeUtils";
|
||||
import { Utils } from '../Utils';
|
||||
@@ -27,7 +29,7 @@ export class FunctionDeclarationObfuscator extends NodeObfuscator {
|
||||
* @param parentNode
|
||||
*/
|
||||
public obfuscateNode (functionDeclarationNode: IFunctionDeclarationNode, parentNode: ITreeNode): void {
|
||||
if (parentNode.type === 'Program') {
|
||||
if (parentNode.type === NodeType.Program) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
const escodegen = require('escodegen');
|
||||
const estraverse = require('estraverse');
|
||||
const NodeType_1 = require("../enums/NodeType");
|
||||
const NodeObfuscator_1 = require('./NodeObfuscator');
|
||||
const NodeUtils_1 = require("../NodeUtils");
|
||||
class MemberExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
|
||||
@@ -28,7 +29,7 @@ class MemberExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
|
||||
content: this.replaceLiteralStringByArrayElement(nodeValue),
|
||||
precedence: escodegen.Precedence.Primary
|
||||
},
|
||||
type: 'Literal',
|
||||
type: NodeType_1.NodeType.Literal,
|
||||
value: nodeValue
|
||||
};
|
||||
delete node.name;
|
||||
|
||||
@@ -6,6 +6,8 @@ import { ILiteralNode } from "../interfaces/nodes/ILiteralNode";
|
||||
import { IMemberExpressionNode } from "../interfaces/nodes/IMemberExpressionNode";
|
||||
import { ITreeNode } from "../interfaces/nodes/ITreeNode";
|
||||
|
||||
import { NodeType } from "../enums/NodeType";
|
||||
|
||||
import { NodeObfuscator } from './NodeObfuscator';
|
||||
import { NodeUtils } from "../NodeUtils";
|
||||
|
||||
@@ -54,7 +56,7 @@ export class MemberExpressionObfuscator extends NodeObfuscator {
|
||||
content : this.replaceLiteralStringByArrayElement(nodeValue),
|
||||
precedence: escodegen.Precedence.Primary
|
||||
},
|
||||
type: 'Literal',
|
||||
type: NodeType.Literal,
|
||||
value: nodeValue
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
const escodegen = require('escodegen');
|
||||
const estraverse = require('estraverse');
|
||||
const NodeType_1 = require("../enums/NodeType");
|
||||
const NodeObfuscator_1 = require('./NodeObfuscator');
|
||||
const NodeUtils_1 = require("../NodeUtils");
|
||||
const Utils_1 = require('../Utils');
|
||||
@@ -42,7 +43,7 @@ class ObjectExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
|
||||
content: Utils_1.Utils.stringToUnicode(nodeValue),
|
||||
precedence: escodegen.Precedence.Primary
|
||||
},
|
||||
type: 'Literal',
|
||||
type: NodeType_1.NodeType.Literal,
|
||||
value: nodeValue
|
||||
};
|
||||
delete node.name;
|
||||
|
||||
@@ -4,12 +4,14 @@ import * as estraverse from 'estraverse';
|
||||
import { IIdentifierNode } from "../interfaces/nodes/IIdentifierNode";
|
||||
import { ILiteralNode } from "../interfaces/nodes/ILiteralNode";
|
||||
import { IObjectExpressionNode } from "../interfaces/nodes/IObjectExpressionNode";
|
||||
import { IPropertyNode } from "../interfaces/nodes/IPropertyNode";
|
||||
import { ITreeNode } from "../interfaces/nodes/ITreeNode";
|
||||
|
||||
import { NodeType } from "../enums/NodeType";
|
||||
|
||||
import { NodeObfuscator } from './NodeObfuscator';
|
||||
import { NodeUtils } from "../NodeUtils";
|
||||
import { Utils } from '../Utils';
|
||||
import {IPropertyNode} from "../interfaces/nodes/IPropertyNode";
|
||||
|
||||
/**
|
||||
* replaces:
|
||||
@@ -76,7 +78,7 @@ export class ObjectExpressionObfuscator extends NodeObfuscator {
|
||||
content : Utils.stringToUnicode(nodeValue),
|
||||
precedence: escodegen.Precedence.Primary
|
||||
},
|
||||
type: 'Literal',
|
||||
type: NodeType.Literal,
|
||||
value: nodeValue
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
const estraverse = require('estraverse');
|
||||
const NodeType_1 = require("../enums/NodeType");
|
||||
const NodeObfuscator_1 = require('./NodeObfuscator');
|
||||
const NodeUtils_1 = require("../NodeUtils");
|
||||
const Utils_1 = require('../Utils');
|
||||
@@ -9,7 +10,7 @@ class VariableDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
|
||||
this.variableNames = new Map();
|
||||
}
|
||||
obfuscateNode(variableDeclarationNode, parentNode) {
|
||||
if (parentNode.type === 'Program') {
|
||||
if (parentNode.type === NodeType_1.NodeType.Program) {
|
||||
return;
|
||||
}
|
||||
this.replaceVariableName(variableDeclarationNode);
|
||||
@@ -36,9 +37,9 @@ class VariableDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
|
||||
estraverse.replace(scopeNode, {
|
||||
enter: (node, parentNode) => {
|
||||
const functionNodes = [
|
||||
'ArrowFunctionExpression',
|
||||
'FunctionDeclaration',
|
||||
'FunctionExpression'
|
||||
NodeType_1.NodeType.ArrowFunctionExpression,
|
||||
NodeType_1.NodeType.FunctionDeclaration,
|
||||
NodeType_1.NodeType.FunctionExpression
|
||||
];
|
||||
if (Utils_1.Utils.arrayContains(functionNodes, node.type)) {
|
||||
estraverse.replace(node, {
|
||||
|
||||
@@ -2,11 +2,13 @@ import * as estraverse from 'estraverse';
|
||||
|
||||
import { ITreeNode } from "../interfaces/nodes/ITreeNode";
|
||||
import { IVariableDeclarationNode } from "../interfaces/nodes/IVariableDeclarationNode";
|
||||
import { IVariableDeclaratorNode } from "../interfaces/nodes/IVariableDeclaratorNode";
|
||||
|
||||
import { NodeType } from "../enums/NodeType";
|
||||
|
||||
import { NodeObfuscator } from './NodeObfuscator';
|
||||
import { NodeUtils } from "../NodeUtils";
|
||||
import { Utils } from '../Utils';
|
||||
import {IVariableDeclaratorNode} from "../interfaces/nodes/IVariableDeclaratorNode";
|
||||
|
||||
/**
|
||||
* replaces:
|
||||
@@ -29,7 +31,7 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
|
||||
* @param parentNode
|
||||
*/
|
||||
public obfuscateNode (variableDeclarationNode: IVariableDeclarationNode, parentNode: ITreeNode): void {
|
||||
if (parentNode.type === 'Program') {
|
||||
if (parentNode.type === NodeType.Program) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -73,9 +75,9 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
|
||||
estraverse.replace(scopeNode, {
|
||||
enter: (node: ITreeNode, parentNode: ITreeNode): any => {
|
||||
const functionNodes: string[] = [
|
||||
'ArrowFunctionExpression',
|
||||
'FunctionDeclaration',
|
||||
'FunctionExpression'
|
||||
NodeType.ArrowFunctionExpression,
|
||||
NodeType.FunctionDeclaration,
|
||||
NodeType.FunctionExpression
|
||||
];
|
||||
|
||||
if (Utils.arrayContains(functionNodes, node.type)) {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
"use strict";
|
||||
const escodegen = require('escodegen');
|
||||
const estraverse = require('estraverse');
|
||||
const AppendState_1 = require('../enums/AppendState');
|
||||
const NodeType_1 = require("../enums/NodeType");
|
||||
const Node_1 = require('./Node');
|
||||
const Utils_1 = require('../Utils');
|
||||
const AppendState_1 = require('../enums/AppendState');
|
||||
class UnicodeArrayNode extends Node_1.Node {
|
||||
constructor(astTree, unicodeArrayName, unicodeArrayRotateValue = 0) {
|
||||
super();
|
||||
@@ -18,7 +19,7 @@ class UnicodeArrayNode extends Node_1.Node {
|
||||
estraverse.replace(this.astTree, {
|
||||
leave: (node, parent) => {
|
||||
switch (node.type) {
|
||||
case 'Program':
|
||||
case NodeType_1.NodeType.Program:
|
||||
node.body.unshift(this.getNode());
|
||||
break;
|
||||
default:
|
||||
@@ -40,19 +41,19 @@ class UnicodeArrayNode extends Node_1.Node {
|
||||
}
|
||||
getNodeStructure() {
|
||||
return {
|
||||
'type': 'VariableDeclaration',
|
||||
'type': NodeType_1.NodeType.VariableDeclaration,
|
||||
'declarations': [
|
||||
{
|
||||
'type': 'VariableDeclarator',
|
||||
'type': NodeType_1.NodeType.VariableDeclarator,
|
||||
'id': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': this.unicodeArrayName
|
||||
},
|
||||
'init': {
|
||||
'type': 'ArrayExpression',
|
||||
'type': NodeType_1.NodeType.ArrayExpression,
|
||||
'elements': this.unicodeArray.map((value) => {
|
||||
return {
|
||||
'type': 'Literal',
|
||||
'type': NodeType_1.NodeType.Literal,
|
||||
'value': value,
|
||||
'raw': `'${value}'`,
|
||||
'x-verbatim-property': {
|
||||
|
||||
@@ -4,11 +4,12 @@ import * as estraverse from 'estraverse';
|
||||
import { IProgramNode } from '../interfaces/nodes/IProgramNode';
|
||||
import { ITreeNode } from '../interfaces/nodes/ITreeNode';
|
||||
|
||||
import { AppendState } from '../enums/AppendState';
|
||||
import { NodeType } from "../enums/NodeType";
|
||||
|
||||
import { Node } from './Node';
|
||||
import { Utils } from '../Utils';
|
||||
|
||||
import { AppendState } from '../enums/AppendState';
|
||||
|
||||
export class UnicodeArrayNode extends Node {
|
||||
/**
|
||||
* @type {number}
|
||||
@@ -63,7 +64,7 @@ export class UnicodeArrayNode extends Node {
|
||||
estraverse.replace(this.astTree, {
|
||||
leave: (node: ITreeNode, parent: ITreeNode): any => {
|
||||
switch (node.type) {
|
||||
case 'Program':
|
||||
case NodeType.Program:
|
||||
(<IProgramNode>node).body.unshift(this.getNode());
|
||||
|
||||
break;
|
||||
@@ -105,19 +106,19 @@ export class UnicodeArrayNode extends Node {
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
return {
|
||||
'type': 'VariableDeclaration',
|
||||
'type': NodeType.VariableDeclaration,
|
||||
'declarations': [
|
||||
{
|
||||
'type': 'VariableDeclarator',
|
||||
'type': NodeType.VariableDeclarator,
|
||||
'id': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': this.unicodeArrayName
|
||||
},
|
||||
'init': {
|
||||
'type': 'ArrayExpression',
|
||||
'type': NodeType.ArrayExpression,
|
||||
'elements': this.unicodeArray.map((value: string) => {
|
||||
return {
|
||||
'type': 'Literal',
|
||||
'type': NodeType.Literal,
|
||||
'value': value,
|
||||
'raw': `'${value}'`,
|
||||
'x-verbatim-property': {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
const estraverse = require('estraverse');
|
||||
const NodeType_1 = require("../enums/NodeType");
|
||||
const Node_1 = require('./Node');
|
||||
class UnicodeArrayRotateFunctionCallNode extends Node_1.Node {
|
||||
constructor(astTree, unicodeArrayRotateFunctionName, unicodeArrayName, unicodeArrayRotateValue) {
|
||||
@@ -14,7 +15,7 @@ class UnicodeArrayRotateFunctionCallNode extends Node_1.Node {
|
||||
estraverse.replace(this.astTree, {
|
||||
leave: (node, parent) => {
|
||||
switch (node.type) {
|
||||
case 'Program':
|
||||
case NodeType_1.NodeType.Program:
|
||||
node.body.unshift(this.getNode());
|
||||
break;
|
||||
default:
|
||||
@@ -25,25 +26,25 @@ class UnicodeArrayRotateFunctionCallNode extends Node_1.Node {
|
||||
}
|
||||
getNodeStructure() {
|
||||
return {
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType_1.NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType_1.NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': this.unicodeArrayRotateFunctionName
|
||||
},
|
||||
'arguments': [
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': this.unicodeArrayName
|
||||
},
|
||||
{
|
||||
'type': 'Literal',
|
||||
'type': NodeType_1.NodeType.Literal,
|
||||
'value': this.unicodeArrayRotateValue,
|
||||
'raw': `'${this.unicodeArrayRotateValue}'`
|
||||
},
|
||||
{
|
||||
'type': 'Literal',
|
||||
'type': NodeType_1.NodeType.Literal,
|
||||
'value': true,
|
||||
'raw': 'true'
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import * as estraverse from 'estraverse';
|
||||
import { IProgramNode } from "../interfaces/nodes/IProgramNode";
|
||||
import { ITreeNode } from "../interfaces/nodes/ITreeNode";
|
||||
|
||||
import { NodeType } from "../enums/NodeType";
|
||||
|
||||
import { Node } from './Node';
|
||||
|
||||
export class UnicodeArrayRotateFunctionCallNode extends Node {
|
||||
@@ -56,7 +58,7 @@ export class UnicodeArrayRotateFunctionCallNode extends Node {
|
||||
estraverse.replace(this.astTree, {
|
||||
leave: (node: ITreeNode, parent: ITreeNode): any => {
|
||||
switch (node.type) {
|
||||
case 'Program':
|
||||
case NodeType.Program:
|
||||
(<IProgramNode>node).body.unshift(this.getNode());
|
||||
|
||||
break;
|
||||
@@ -73,25 +75,25 @@ export class UnicodeArrayRotateFunctionCallNode extends Node {
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
return {
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': this.unicodeArrayRotateFunctionName
|
||||
},
|
||||
'arguments': [
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': this.unicodeArrayName
|
||||
},
|
||||
{
|
||||
'type': 'Literal',
|
||||
'type': NodeType.Literal,
|
||||
'value': this.unicodeArrayRotateValue,
|
||||
'raw': `'${this.unicodeArrayRotateValue}'`
|
||||
},
|
||||
{
|
||||
'type': 'Literal',
|
||||
'type': NodeType.Literal,
|
||||
'value': true,
|
||||
'raw': 'true'
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
const estraverse = require('estraverse');
|
||||
const NodeType_1 = require("../enums/NodeType");
|
||||
const Node_1 = require('./Node');
|
||||
const Utils_1 = require('../Utils');
|
||||
class UnicodeArrayRotateFunctionNode extends Node_1.Node {
|
||||
@@ -14,7 +15,7 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
|
||||
estraverse.replace(this.astTree, {
|
||||
leave: (node, parent) => {
|
||||
switch (node.type) {
|
||||
case 'Program':
|
||||
case NodeType_1.NodeType.Program:
|
||||
node.body.push(this.getNode());
|
||||
break;
|
||||
default:
|
||||
@@ -28,49 +29,49 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
|
||||
}
|
||||
getNodeStructure() {
|
||||
return {
|
||||
'type': 'FunctionExpression',
|
||||
'type': NodeType_1.NodeType.FunctionExpression,
|
||||
'id': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': this.unicodeArrayRotateFunctionName
|
||||
},
|
||||
'params': [
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'times'
|
||||
},
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'reverse'
|
||||
}
|
||||
],
|
||||
'defaults': [],
|
||||
'body': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType_1.NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'IfStatement',
|
||||
'type': NodeType_1.NodeType.IfStatement,
|
||||
'test': {
|
||||
'type': 'BinaryExpression',
|
||||
'type': NodeType_1.NodeType.BinaryExpression,
|
||||
'operator': '<',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'times'
|
||||
},
|
||||
'right': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType_1.NodeType.Literal,
|
||||
'value': 0,
|
||||
'raw': '0'
|
||||
}
|
||||
},
|
||||
'consequent': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType_1.NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'ReturnStatement',
|
||||
'type': NodeType_1.NodeType.ReturnStatement,
|
||||
'argument': null
|
||||
}
|
||||
]
|
||||
@@ -78,23 +79,23 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
|
||||
'alternate': null
|
||||
},
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType_1.NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'AssignmentExpression',
|
||||
'type': NodeType_1.NodeType.AssignmentExpression,
|
||||
'operator': '=',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'reverse'
|
||||
},
|
||||
'right': {
|
||||
'type': 'LogicalExpression',
|
||||
'type': NodeType_1.NodeType.LogicalExpression,
|
||||
'operator': '||',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'reverse'
|
||||
},
|
||||
'right': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType_1.NodeType.Literal,
|
||||
'value': false,
|
||||
'raw': 'false'
|
||||
}
|
||||
@@ -102,12 +103,12 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
|
||||
}
|
||||
},
|
||||
{
|
||||
'type': 'VariableDeclaration',
|
||||
'type': NodeType_1.NodeType.VariableDeclaration,
|
||||
'declarations': [
|
||||
{
|
||||
'type': 'VariableDeclarator',
|
||||
'type': NodeType_1.NodeType.VariableDeclarator,
|
||||
'id': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
},
|
||||
'init': null
|
||||
@@ -116,53 +117,53 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
|
||||
'kind': 'var'
|
||||
},
|
||||
{
|
||||
'type': 'WhileStatement',
|
||||
'type': NodeType_1.NodeType.WhileStatement,
|
||||
'test': {
|
||||
'type': 'UpdateExpression',
|
||||
'type': NodeType_1.NodeType.UpdateExpression,
|
||||
'operator': '--',
|
||||
'argument': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'times'
|
||||
},
|
||||
'prefix': false
|
||||
},
|
||||
'body': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType_1.NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'IfStatement',
|
||||
'type': NodeType_1.NodeType.IfStatement,
|
||||
'test': {
|
||||
'type': 'UnaryExpression',
|
||||
'type': NodeType_1.NodeType.UnaryExpression,
|
||||
'operator': '!',
|
||||
'argument': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'reverse'
|
||||
},
|
||||
'prefix': true
|
||||
},
|
||||
'consequent': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType_1.NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType_1.NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'AssignmentExpression',
|
||||
'type': NodeType_1.NodeType.AssignmentExpression,
|
||||
'operator': '=',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
},
|
||||
'right': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType_1.NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'MemberExpression',
|
||||
'type': NodeType_1.NodeType.MemberExpression,
|
||||
'computed': true,
|
||||
'object': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
'property': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType_1.NodeType.Literal,
|
||||
'name': 'pop',
|
||||
'x-verbatim-property': Utils_1.Utils.stringToUnicode('pop')
|
||||
}
|
||||
@@ -172,25 +173,25 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
|
||||
}
|
||||
},
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType_1.NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType_1.NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'MemberExpression',
|
||||
'type': NodeType_1.NodeType.MemberExpression,
|
||||
'computed': true,
|
||||
'object': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
'property': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType_1.NodeType.Literal,
|
||||
'name': 'unshift',
|
||||
'x-verbatim-property': Utils_1.Utils.stringToUnicode('unshift')
|
||||
}
|
||||
},
|
||||
'arguments': [
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
}
|
||||
]
|
||||
@@ -199,28 +200,28 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
|
||||
]
|
||||
},
|
||||
'alternate': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType_1.NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType_1.NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'AssignmentExpression',
|
||||
'type': NodeType_1.NodeType.AssignmentExpression,
|
||||
'operator': '=',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
},
|
||||
'right': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType_1.NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'MemberExpression',
|
||||
'type': NodeType_1.NodeType.MemberExpression,
|
||||
'computed': true,
|
||||
'object': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
'property': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType_1.NodeType.Literal,
|
||||
'name': 'shift',
|
||||
'x-verbatim-property': Utils_1.Utils.stringToUnicode('shift')
|
||||
}
|
||||
@@ -230,25 +231,25 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
|
||||
}
|
||||
},
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType_1.NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType_1.NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'MemberExpression',
|
||||
'type': NodeType_1.NodeType.MemberExpression,
|
||||
'computed': true,
|
||||
'object': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
'property': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType_1.NodeType.Literal,
|
||||
'name': 'push',
|
||||
'x-verbatim-property': Utils_1.Utils.stringToUnicode('push')
|
||||
}
|
||||
},
|
||||
'arguments': [
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType_1.NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
}
|
||||
]
|
||||
|
||||
@@ -3,6 +3,8 @@ import * as estraverse from 'estraverse';
|
||||
import { IProgramNode } from '../interfaces/nodes/IProgramNode';
|
||||
import { ITreeNode } from '../interfaces/nodes/ITreeNode';
|
||||
|
||||
import { NodeType } from "../enums/NodeType";
|
||||
|
||||
import { Node } from './Node';
|
||||
import { Utils } from '../Utils';
|
||||
|
||||
@@ -48,7 +50,7 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
estraverse.replace(this.astTree, {
|
||||
leave: (node: ITreeNode, parent: ITreeNode): any => {
|
||||
switch (node.type) {
|
||||
case 'Program':
|
||||
case NodeType.Program:
|
||||
(<IProgramNode>node).body.push(this.getNode());
|
||||
|
||||
break;
|
||||
@@ -72,49 +74,49 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
return {
|
||||
'type': 'FunctionExpression',
|
||||
'type': NodeType.FunctionExpression,
|
||||
'id': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': this.unicodeArrayRotateFunctionName
|
||||
},
|
||||
'params': [
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'times'
|
||||
},
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'reverse'
|
||||
}
|
||||
],
|
||||
'defaults': [],
|
||||
'body': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'IfStatement',
|
||||
'type': NodeType.IfStatement,
|
||||
'test': {
|
||||
'type': 'BinaryExpression',
|
||||
'type': NodeType.BinaryExpression,
|
||||
'operator': '<',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'times'
|
||||
},
|
||||
'right': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType.Literal,
|
||||
'value': 0,
|
||||
'raw': '0'
|
||||
}
|
||||
},
|
||||
'consequent': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'ReturnStatement',
|
||||
'type': NodeType.ReturnStatement,
|
||||
'argument': null
|
||||
}
|
||||
]
|
||||
@@ -122,23 +124,23 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
'alternate': null
|
||||
},
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'AssignmentExpression',
|
||||
'type': NodeType.AssignmentExpression,
|
||||
'operator': '=',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'reverse'
|
||||
},
|
||||
'right': {
|
||||
'type': 'LogicalExpression',
|
||||
'type': NodeType.LogicalExpression,
|
||||
'operator': '||',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'reverse'
|
||||
},
|
||||
'right': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType.Literal,
|
||||
'value': false,
|
||||
'raw': 'false'
|
||||
}
|
||||
@@ -146,12 +148,12 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
}
|
||||
},
|
||||
{
|
||||
'type': 'VariableDeclaration',
|
||||
'type': NodeType.VariableDeclaration,
|
||||
'declarations': [
|
||||
{
|
||||
'type': 'VariableDeclarator',
|
||||
'type': NodeType.VariableDeclarator,
|
||||
'id': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
},
|
||||
'init': null
|
||||
@@ -160,53 +162,53 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
'kind': 'var'
|
||||
},
|
||||
{
|
||||
'type': 'WhileStatement',
|
||||
'type': NodeType.WhileStatement,
|
||||
'test': {
|
||||
'type': 'UpdateExpression',
|
||||
'type': NodeType.UpdateExpression,
|
||||
'operator': '--',
|
||||
'argument': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'times'
|
||||
},
|
||||
'prefix': false
|
||||
},
|
||||
'body': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'IfStatement',
|
||||
'type': NodeType.IfStatement,
|
||||
'test': {
|
||||
'type': 'UnaryExpression',
|
||||
'type': NodeType.UnaryExpression,
|
||||
'operator': '!',
|
||||
'argument': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'reverse'
|
||||
},
|
||||
'prefix': true
|
||||
},
|
||||
'consequent': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'AssignmentExpression',
|
||||
'type': NodeType.AssignmentExpression,
|
||||
'operator': '=',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
},
|
||||
'right': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'MemberExpression',
|
||||
'type': NodeType.MemberExpression,
|
||||
'computed': true,
|
||||
'object': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
'property': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType.Literal,
|
||||
'name': 'pop',
|
||||
'x-verbatim-property': Utils.stringToUnicode('pop')
|
||||
}
|
||||
@@ -216,25 +218,25 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
}
|
||||
},
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'MemberExpression',
|
||||
'type': NodeType.MemberExpression,
|
||||
'computed': true,
|
||||
'object': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
'property': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType.Literal,
|
||||
'name': 'unshift',
|
||||
'x-verbatim-property': Utils.stringToUnicode('unshift')
|
||||
}
|
||||
},
|
||||
'arguments': [
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
}
|
||||
]
|
||||
@@ -243,28 +245,28 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
]
|
||||
},
|
||||
'alternate': {
|
||||
'type': 'BlockStatement',
|
||||
'type': NodeType.BlockStatement,
|
||||
'body': [
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'AssignmentExpression',
|
||||
'type': NodeType.AssignmentExpression,
|
||||
'operator': '=',
|
||||
'left': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
},
|
||||
'right': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'MemberExpression',
|
||||
'type': NodeType.MemberExpression,
|
||||
'computed': true,
|
||||
'object': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
'property': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType.Literal,
|
||||
'name': 'shift',
|
||||
'x-verbatim-property': Utils.stringToUnicode('shift')
|
||||
}
|
||||
@@ -274,25 +276,25 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
}
|
||||
},
|
||||
{
|
||||
'type': 'ExpressionStatement',
|
||||
'type': NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
'type': 'CallExpression',
|
||||
'type': NodeType.CallExpression,
|
||||
'callee': {
|
||||
'type': 'MemberExpression',
|
||||
'type': NodeType.MemberExpression,
|
||||
'computed': true,
|
||||
'object': {
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'array'
|
||||
},
|
||||
'property': {
|
||||
'type': 'Literal',
|
||||
'type': NodeType.Literal,
|
||||
'name': 'push',
|
||||
'x-verbatim-property': Utils.stringToUnicode('push')
|
||||
}
|
||||
},
|
||||
'arguments': [
|
||||
{
|
||||
'type': 'Identifier',
|
||||
'type': NodeType.Identifier,
|
||||
'name': 'temp'
|
||||
}
|
||||
]
|
||||
|
||||
+1
-5
@@ -136,11 +136,7 @@
|
||||
"check-module",
|
||||
"check-function"
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"check-format",
|
||||
"allow-leading-underscore"
|
||||
],
|
||||
"variable-name": false,
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
|
||||
Reference in New Issue
Block a user