Refactoring

This commit is contained in:
kachalov
2016-05-16 13:22:12 +03:00
parent b145ff369a
commit 5f6e29f763
4 changed files with 13 additions and 40 deletions
@@ -41,29 +41,20 @@ class VariableDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
else {
scopeNode = variableParentNode;
}
let isNodeAfterVariableDeclaratorFlag = false, isNodeBeforeVariableDeclaratorFlag = true, functionParentScope, functionNextNode, functionIndex = -1;
let isNodeAfterVariableDeclaratorFlag = false;
estraverse.replace(scopeNode, {
enter: (node, parentNode) => {
if (node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression' ||
node.type === 'ArrowFunctionExpression') {
functionParentScope = NodeUtils_1.NodeUtils.getNodeScope(node);
if (NodeUtils_1.NodeUtils.isBlockStatementNode(functionParentScope)) {
functionIndex = functionParentScope.body.indexOf(node);
if (functionIndex >= 0) {
functionNextNode = functionParentScope.body[functionIndex + 1];
estraverse.replace(node, {
enter: (node, parentNode) => {
this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);
}
}
isNodeAfterVariableDeclaratorFlag = true;
}
if (functionNextNode && isNodeBeforeVariableDeclaratorFlag && node === functionNextNode) {
isNodeAfterVariableDeclaratorFlag = false;
functionNextNode = undefined;
functionIndex = -1;
});
}
if (node === variableDeclarationNode) {
isNodeAfterVariableDeclaratorFlag = true;
isNodeBeforeVariableDeclaratorFlag = false;
}
if (isNodeAfterVariableDeclaratorFlag) {
this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);
@@ -76,13 +76,8 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
scopeNode = variableParentNode;
}
let isNodeAfterVariableDeclaratorFlag: boolean = false,
isNodeBeforeVariableDeclaratorFlag: boolean = true,
functionParentScope: ITreeNode,
functionNextNode: ITreeNode,
functionIndex: number = -1;
let isNodeAfterVariableDeclaratorFlag: boolean = false;
//TODO: REFACTOR THIS
estraverse.replace(scopeNode, {
enter: (node: ITreeNode, parentNode: ITreeNode) => {
if (
@@ -90,28 +85,15 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
node.type === 'FunctionExpression' ||
node.type === 'ArrowFunctionExpression'
) {
functionParentScope = NodeUtils.getNodeScope(node);
if (NodeUtils.isBlockStatementNode(functionParentScope)) {
functionIndex = functionParentScope.body.indexOf(node);
if (functionIndex >= 0) {
functionNextNode = functionParentScope.body[functionIndex + 1];
estraverse.replace(node, {
enter: (node: ITreeNode, parentNode: ITreeNode) => {
this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);
}
}
isNodeAfterVariableDeclaratorFlag = true;
}
if (functionNextNode && isNodeBeforeVariableDeclaratorFlag && node === functionNextNode) {
isNodeAfterVariableDeclaratorFlag = false;
functionNextNode = undefined;
functionIndex = -1;
});
}
if (node === variableDeclarationNode) {
isNodeAfterVariableDeclaratorFlag = true;
isNodeBeforeVariableDeclaratorFlag = false;
}
if (isNodeAfterVariableDeclaratorFlag) {
@@ -120,4 +102,4 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
}
});
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
var JavaScriptObfuscator = require('../index.js');
var obfuscatedCode = JavaScriptObfuscator.obfuscate(`
(function(){
(function(){
var result = 1,
term1 = 0,
term2 = 1,
+1 -1
View File
@@ -2,7 +2,7 @@ var JavaScriptObfuscator = require('../index.js');
var obfuscatedCode = JavaScriptObfuscator.obfuscate(
`
(function(){
(function(){
var result = 1,
term1 = 0,
term2 = 1,