mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
trying to increase performance
This commit is contained in:
@@ -15,7 +15,7 @@ import { readFileAsString } from '../../helpers/readFileAsString';
|
||||
|
||||
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
|
||||
import { Node } from '../../../src/node/Node';
|
||||
import { NodeMocks } from '../../mocks/NodeMocks';
|
||||
import { Nodes } from '../../../src/node/Nodes';
|
||||
import { NodeUtils } from '../../../src/node/NodeUtils';
|
||||
|
||||
/**
|
||||
@@ -157,7 +157,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
expectedStackTraceData: IStackTraceData[];
|
||||
|
||||
it('should returns correct IStackTraceData - variant #1: basic-1', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/basic-1.js')
|
||||
)
|
||||
@@ -204,7 +204,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
});
|
||||
|
||||
it('should returns correct IStackTraceData - variant #2: basic-2', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/basic-2.js')
|
||||
)
|
||||
@@ -240,7 +240,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
});
|
||||
|
||||
it('should returns correct IStackTraceData - variant #3: deep conditions nesting', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/deep-conditions-nesting.js')
|
||||
)
|
||||
@@ -276,7 +276,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
});
|
||||
|
||||
it('should returns correct IStackTraceData - variant #4: call before declaration', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/call-before-declaration.js')
|
||||
)
|
||||
@@ -296,7 +296,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
});
|
||||
|
||||
it('should returns correct IStackTraceData - variant #5: call expression of object member #1', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/call-expression-of-object-member-1.js')
|
||||
)
|
||||
@@ -352,7 +352,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
});
|
||||
|
||||
it('should returns correct IStackTraceData - variant #5: call expression of object member #2', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/call-expression-of-object-member-2.js')
|
||||
)
|
||||
@@ -377,7 +377,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
});
|
||||
|
||||
it('should returns correct IStackTraceData - variant #6: no call expressions', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/no-call-expressions.js')
|
||||
)
|
||||
@@ -391,7 +391,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
});
|
||||
|
||||
it('should returns correct IStackTraceData - variant #7: only call expression', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/only-call-expression.js')
|
||||
)
|
||||
@@ -405,7 +405,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
});
|
||||
|
||||
it('should returns correct IStackTraceData - variant #8: self-invoking functions', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/self-invoking-functions.js')
|
||||
)
|
||||
@@ -437,7 +437,7 @@ describe('StackTraceAnalyzer', () => {
|
||||
});
|
||||
|
||||
it('should returns correct IStackTraceData - variant #9: no recursion', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/no-recursion.js')
|
||||
)
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
import * as escodegen from 'escodegen';
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
import { TStatement } from '../../src/types/node/TStatement';
|
||||
|
||||
import { NodeType } from '../../src/enums/NodeType';
|
||||
|
||||
export class NodeMocks {
|
||||
/**
|
||||
* @param bodyNodes
|
||||
* @returns {ESTree.Program}
|
||||
*/
|
||||
public static getProgramNode (bodyNodes: TStatement[] = []): ESTree.Program {
|
||||
return {
|
||||
type: NodeType.Program,
|
||||
body: bodyNodes,
|
||||
sourceType: 'script',
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bodyNodes
|
||||
* @returns {ESTree.BlockStatement}
|
||||
*/
|
||||
public static getBlockStatementNode (bodyNodes: ESTree.Statement[] = []): ESTree.BlockStatement {
|
||||
return {
|
||||
type: NodeType.BlockStatement,
|
||||
body: bodyNodes,
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bodyNodes
|
||||
* @returns {ESTree.CatchClause}
|
||||
*/
|
||||
public static getCatchClauseNode (bodyNodes: ESTree.Statement[] = []): ESTree.CatchClause {
|
||||
return {
|
||||
type: NodeType.CatchClause,
|
||||
param: NodeMocks.getIdentifierNode('err'),
|
||||
body: NodeMocks.getBlockStatementNode(bodyNodes),
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callee
|
||||
* @param args
|
||||
* @returns {ESTree.CallExpression}
|
||||
*/
|
||||
public static getCallExpressionNode (
|
||||
callee: ESTree.Expression,
|
||||
args: ESTree.Expression[] | ESTree.SpreadElement[] = []
|
||||
): ESTree.CallExpression {
|
||||
return {
|
||||
type: NodeType.CallExpression,
|
||||
callee: callee,
|
||||
arguments: args,
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param expression
|
||||
* @returns {ESTree.ExpressionStatement}
|
||||
*/
|
||||
public static getExpressionStatementNode (
|
||||
expression: ESTree.Expression = NodeMocks.getIdentifierNode()
|
||||
): ESTree.ExpressionStatement {
|
||||
return {
|
||||
type: NodeType.ExpressionStatement,
|
||||
expression: expression,
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param functionName
|
||||
* @param blockStatementNode
|
||||
* @param params
|
||||
* @returns {ESTree.FunctionDeclaration}
|
||||
*/
|
||||
public static getFunctionDeclarationNode (
|
||||
functionName: string,
|
||||
blockStatementNode: ESTree.BlockStatement,
|
||||
params: ESTree.Identifier[] = []
|
||||
): ESTree.FunctionDeclaration {
|
||||
return {
|
||||
type: NodeType.FunctionDeclaration,
|
||||
id: NodeMocks.getIdentifierNode(functionName),
|
||||
params: params,
|
||||
body: blockStatementNode,
|
||||
generator: false,
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param blockStatementNode
|
||||
* @returns {ESTree.IfStatement}
|
||||
*/
|
||||
public static getIfStatementNode (blockStatementNode: ESTree.BlockStatement): ESTree.IfStatement {
|
||||
return {
|
||||
type: 'IfStatement',
|
||||
test: {
|
||||
type: 'Literal',
|
||||
value: true,
|
||||
raw: 'true',
|
||||
obfuscated: false
|
||||
},
|
||||
consequent: blockStatementNode,
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param identifierName
|
||||
* @returns {ESTree.Identifier}
|
||||
*/
|
||||
public static getIdentifierNode (identifierName: string = 'identifier'): ESTree.Identifier {
|
||||
return {
|
||||
type: NodeType.Identifier,
|
||||
name: identifierName,
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
* @returns {ESTree.Literal}
|
||||
*/
|
||||
public static getLiteralNode (value: boolean|number|string = 'value'): ESTree.Literal {
|
||||
return {
|
||||
type: NodeType.Literal,
|
||||
value: value,
|
||||
raw: `'${value}'`,
|
||||
'x-verbatim-property': {
|
||||
content: `'${value}'`,
|
||||
precedence: escodegen.Precedence.Primary
|
||||
},
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object
|
||||
* @param property
|
||||
* @return {ESTree.MemberExpression}
|
||||
*/
|
||||
public static getMemberExpressionNode (
|
||||
object: ESTree.Identifier,
|
||||
property: ESTree.Identifier|ESTree.Literal
|
||||
): ESTree.MemberExpression {
|
||||
return {
|
||||
type: NodeType.MemberExpression,
|
||||
computed: false,
|
||||
object: object,
|
||||
property: property,
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param declarations
|
||||
* @param kind
|
||||
* @returns {ESTree.VariableDeclaration}
|
||||
*/
|
||||
public static getVariableDeclarationNode (
|
||||
declarations: ESTree.VariableDeclarator[] = [],
|
||||
kind: 'var' | 'let' | 'const' = 'var'
|
||||
): ESTree.VariableDeclaration {
|
||||
return {
|
||||
type: NodeType.VariableDeclaration,
|
||||
declarations: declarations,
|
||||
kind: kind,
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param init
|
||||
* @returns {ESTree.VariableDeclarator}
|
||||
*/
|
||||
public static getVariableDeclaratorNode (id: ESTree.Identifier, init: any): ESTree.VariableDeclarator {
|
||||
return {
|
||||
type: NodeType.VariableDeclarator,
|
||||
id: id,
|
||||
init: init,
|
||||
obfuscated: false
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import { readFileAsString } from '../../helpers/readFileAsString';
|
||||
|
||||
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
|
||||
import { NodeAppender } from '../../../src/node/NodeAppender';
|
||||
import { NodeMocks } from '../../mocks/NodeMocks';
|
||||
import { Nodes } from '../../../src/node/Nodes';
|
||||
import { NodeUtils } from '../../../src/node/NodeUtils';
|
||||
|
||||
describe('NodeAppender', () => {
|
||||
@@ -28,13 +28,13 @@ describe('NodeAppender', () => {
|
||||
var test = 1;
|
||||
`);
|
||||
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node.js')
|
||||
)
|
||||
);
|
||||
|
||||
expectedAstTree = NodeMocks.getProgramNode(
|
||||
expectedAstTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-expected.js')
|
||||
)
|
||||
@@ -68,13 +68,13 @@ describe('NodeAppender', () => {
|
||||
});
|
||||
|
||||
it('should append node into first and deepest function call in calls trace - variant #1', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1.js')
|
||||
)
|
||||
);
|
||||
|
||||
expectedAstTree = NodeMocks.getProgramNode(
|
||||
expectedAstTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1-expected.js')
|
||||
)
|
||||
@@ -87,13 +87,13 @@ describe('NodeAppender', () => {
|
||||
});
|
||||
|
||||
it('should append node into first and deepest function call in calls trace - variant #2', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2.js')
|
||||
)
|
||||
);
|
||||
|
||||
expectedAstTree = NodeMocks.getProgramNode(
|
||||
expectedAstTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2-expected.js')
|
||||
)
|
||||
@@ -109,7 +109,7 @@ describe('NodeAppender', () => {
|
||||
let astTree: ESTree.Program;
|
||||
|
||||
beforeEach(() => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index.js')
|
||||
|
||||
@@ -118,7 +118,7 @@ describe('NodeAppender', () => {
|
||||
});
|
||||
|
||||
it('should append node into deepest function call by specified index in calls trace - variant #1', () => {
|
||||
expectedAstTree = NodeMocks.getProgramNode(
|
||||
expectedAstTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-1-expected.js')
|
||||
|
||||
@@ -132,7 +132,7 @@ describe('NodeAppender', () => {
|
||||
});
|
||||
|
||||
it('should append node into deepest function call by specified index in calls trace - variant #2', () => {
|
||||
expectedAstTree = NodeMocks.getProgramNode(
|
||||
expectedAstTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-2-expected.js')
|
||||
|
||||
@@ -146,12 +146,12 @@ describe('NodeAppender', () => {
|
||||
});
|
||||
|
||||
it('should append node into deepest function call by specified index in calls trace - variant #3', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3.js')
|
||||
)
|
||||
);
|
||||
expectedAstTree = NodeMocks.getProgramNode(
|
||||
expectedAstTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3-expected.js')
|
||||
)
|
||||
@@ -193,13 +193,13 @@ describe('NodeAppender', () => {
|
||||
var test = 1;
|
||||
`);
|
||||
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/insert-node-at-index.js')
|
||||
)
|
||||
);
|
||||
|
||||
expectedAstTree = NodeMocks.getProgramNode(
|
||||
expectedAstTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/insert-node-at-index-expected.js')
|
||||
)
|
||||
@@ -226,13 +226,13 @@ describe('NodeAppender', () => {
|
||||
var test = 1;
|
||||
`);
|
||||
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
astTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/prepend-node.js')
|
||||
)
|
||||
);
|
||||
|
||||
expectedAstTree = NodeMocks.getProgramNode(
|
||||
expectedAstTree = Nodes.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/node-appender/prepend-node-expected.js')
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as ESTree from 'estree';
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { NodeMocks } from '../../mocks/NodeMocks';
|
||||
import { Nodes } from '../../../src/node/Nodes';
|
||||
import { NodeUtils } from '../../../src/node/NodeUtils';
|
||||
|
||||
describe('NodeUtils', () => {
|
||||
@@ -11,10 +11,10 @@ describe('NodeUtils', () => {
|
||||
expectedLiteralNode: any;
|
||||
|
||||
beforeEach(() => {
|
||||
literalNode = NodeMocks.getLiteralNode();
|
||||
literalNode = Nodes.getLiteralNode('value');
|
||||
delete literalNode['x-verbatim-property'];
|
||||
|
||||
expectedLiteralNode = NodeMocks.getLiteralNode();
|
||||
expectedLiteralNode = Nodes.getLiteralNode('value');
|
||||
|
||||
NodeUtils.addXVerbatimPropertyToLiterals(literalNode);
|
||||
});
|
||||
@@ -37,17 +37,17 @@ describe('NodeUtils', () => {
|
||||
var abc = 'cde';
|
||||
`;
|
||||
|
||||
identifierNode = NodeMocks.getIdentifierNode('abc');
|
||||
identifierNode = Nodes.getIdentifierNode('abc');
|
||||
|
||||
literalNode = NodeMocks.getLiteralNode('cde');
|
||||
literalNode = Nodes.getLiteralNode('cde');
|
||||
|
||||
variableDeclaratorNode = NodeMocks.getVariableDeclaratorNode(identifierNode, literalNode);
|
||||
variableDeclaratorNode = Nodes.getVariableDeclaratorNode(identifierNode, literalNode);
|
||||
|
||||
variableDeclarationNode = NodeMocks.getVariableDeclarationNode([
|
||||
variableDeclarationNode = Nodes.getVariableDeclarationNode([
|
||||
variableDeclaratorNode
|
||||
]);
|
||||
|
||||
programNode = NodeMocks.getProgramNode([
|
||||
programNode = Nodes.getProgramNode([
|
||||
variableDeclarationNode
|
||||
]);
|
||||
|
||||
@@ -69,11 +69,11 @@ describe('NodeUtils', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
structure = [
|
||||
NodeMocks.getProgramNode([
|
||||
NodeMocks.getVariableDeclarationNode([
|
||||
NodeMocks.getVariableDeclaratorNode(
|
||||
NodeMocks.getIdentifierNode('abc'),
|
||||
NodeMocks.getLiteralNode('cde')
|
||||
Nodes.getProgramNode([
|
||||
Nodes.getVariableDeclarationNode([
|
||||
Nodes.getVariableDeclaratorNode(
|
||||
Nodes.getIdentifierNode('abc'),
|
||||
Nodes.getLiteralNode('cde')
|
||||
)
|
||||
])
|
||||
])
|
||||
@@ -92,10 +92,10 @@ describe('NodeUtils', () => {
|
||||
expressionStatementNode2: ESTree.ExpressionStatement;
|
||||
|
||||
beforeEach(() => {
|
||||
expressionStatementNode1 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode2 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode1 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode2 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
|
||||
blockStatementNode = NodeMocks.getBlockStatementNode([
|
||||
blockStatementNode = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode1,
|
||||
expressionStatementNode2
|
||||
]);
|
||||
@@ -128,31 +128,37 @@ describe('NodeUtils', () => {
|
||||
programNode: ESTree.Program;
|
||||
|
||||
beforeEach(() => {
|
||||
expressionStatementNode1 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode2 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode3 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode1 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode2 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode3 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
|
||||
ifStatementBlockStatementNode2 = NodeMocks.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode2 = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode2,
|
||||
expressionStatementNode3
|
||||
]);
|
||||
|
||||
ifStatementNode2 = NodeMocks.getIfStatementNode(ifStatementBlockStatementNode2);
|
||||
ifStatementNode2 = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementBlockStatementNode2
|
||||
);
|
||||
|
||||
ifStatementBlockStatementNode1 = NodeMocks.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode1 = Nodes.getBlockStatementNode([
|
||||
ifStatementNode2
|
||||
]);
|
||||
|
||||
ifStatementNode1 = NodeMocks.getIfStatementNode(ifStatementBlockStatementNode1);
|
||||
ifStatementNode1 = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementBlockStatementNode1
|
||||
);
|
||||
|
||||
functionDeclarationBlockStatementNode = NodeMocks.getBlockStatementNode([
|
||||
functionDeclarationBlockStatementNode = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode1,
|
||||
ifStatementNode1
|
||||
]);
|
||||
|
||||
functionDeclarationNode = NodeMocks.getFunctionDeclarationNode('test', functionDeclarationBlockStatementNode);
|
||||
functionDeclarationNode = Nodes.getFunctionDeclarationNode('test', [], functionDeclarationBlockStatementNode);
|
||||
|
||||
programNode = NodeMocks.getProgramNode([
|
||||
programNode = Nodes.getProgramNode([
|
||||
functionDeclarationNode
|
||||
]);
|
||||
|
||||
@@ -203,37 +209,43 @@ describe('NodeUtils', () => {
|
||||
programNode: ESTree.Program;
|
||||
|
||||
beforeEach(() => {
|
||||
expressionStatementNode1 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode2 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode3 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode1 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode2 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode3 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
|
||||
ifStatementBlockStatementNode2 = NodeMocks.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode2 = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode3
|
||||
]);
|
||||
|
||||
ifStatementNode2 = NodeMocks.getIfStatementNode(ifStatementBlockStatementNode2);
|
||||
ifStatementNode2 = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementBlockStatementNode2
|
||||
);
|
||||
|
||||
functionDeclarationBlockStatementNode2 = NodeMocks.getBlockStatementNode([
|
||||
functionDeclarationBlockStatementNode2 = Nodes.getBlockStatementNode([
|
||||
ifStatementNode2,
|
||||
expressionStatementNode2
|
||||
]);
|
||||
|
||||
functionDeclarationNode2 = NodeMocks.getFunctionDeclarationNode('test', functionDeclarationBlockStatementNode2);
|
||||
functionDeclarationNode2 = Nodes.getFunctionDeclarationNode('test', [], functionDeclarationBlockStatementNode2);
|
||||
|
||||
ifStatementBlockStatementNode1 = NodeMocks.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode1 = Nodes.getBlockStatementNode([
|
||||
functionDeclarationNode2
|
||||
]);
|
||||
|
||||
ifStatementNode1 = NodeMocks.getIfStatementNode(ifStatementBlockStatementNode1);
|
||||
ifStatementNode1 = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementBlockStatementNode1
|
||||
);
|
||||
|
||||
functionDeclarationBlockStatementNode1 = NodeMocks.getBlockStatementNode([
|
||||
functionDeclarationBlockStatementNode1 = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode1,
|
||||
ifStatementNode1
|
||||
]);
|
||||
|
||||
functionDeclarationNode1 = NodeMocks.getFunctionDeclarationNode('test', functionDeclarationBlockStatementNode1);
|
||||
functionDeclarationNode1 = Nodes.getFunctionDeclarationNode('test', [], functionDeclarationBlockStatementNode1);
|
||||
|
||||
programNode = NodeMocks.getProgramNode([
|
||||
programNode = Nodes.getProgramNode([
|
||||
functionDeclarationNode1
|
||||
]);
|
||||
|
||||
@@ -277,19 +289,22 @@ describe('NodeUtils', () => {
|
||||
programNode: ESTree.Program;
|
||||
|
||||
beforeEach(() => {
|
||||
expressionStatementNode1 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode2 = NodeMocks.getExpressionStatementNode();
|
||||
expressionStatementNode1 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode2 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
|
||||
ifStatementBlockStatementNode = NodeMocks.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode1,
|
||||
expressionStatementNode2
|
||||
]);
|
||||
|
||||
ifStatementNode = NodeMocks.getIfStatementNode(ifStatementBlockStatementNode);
|
||||
ifStatementNode = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementBlockStatementNode
|
||||
);
|
||||
});
|
||||
|
||||
it('should parentize given AST-tree with `ProgramNode` as root node', () => {
|
||||
programNode = NodeMocks.getProgramNode([
|
||||
programNode = Nodes.getProgramNode([
|
||||
ifStatementNode
|
||||
]);
|
||||
|
||||
@@ -303,7 +318,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
it('should parentize given AST-tree', () => {
|
||||
programNode = NodeMocks.getProgramNode([
|
||||
programNode = Nodes.getProgramNode([
|
||||
ifStatementNode
|
||||
]);
|
||||
programNode['parentNode'] = programNode;
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { TCustomNodeFactory } from '../../../src/types/container/TCustomNodeFactory';
|
||||
|
||||
import { ICustomNode } from '../../../src/interfaces/custom-nodes/ICustomNode';
|
||||
import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
|
||||
import { IStorage } from '../../../src/interfaces/storages/IStorage';
|
||||
|
||||
import { CustomNodes } from '../../../src/enums/container/CustomNodes';
|
||||
|
||||
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
|
||||
|
||||
describe('ControlFlowStorage', () => {
|
||||
describe('toString (): string', () => {
|
||||
it('should return correct ControlFlowStorage data after `.toString()` call', () => {
|
||||
const key1: string = 'key1';
|
||||
const key2: string = 'key2';
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade({
|
||||
controlFlowFlattening: true
|
||||
});
|
||||
const customNodeFactory: TCustomNodeFactory = inversifyContainerFacade
|
||||
.get<TCustomNodeFactory>(ServiceIdentifiers['Factory<ICustomNode>']);
|
||||
const controlFlowStorage: IStorage <ICustomNode> = inversifyContainerFacade
|
||||
.get<IStorage<ICustomNode>>(ServiceIdentifiers['IStorage<ICustomNode>']);
|
||||
const controlFlowStorageCallNode1: ICustomNode = customNodeFactory(CustomNodes.ControlFlowStorageCallNode);
|
||||
const controlFlowStorageCallNode2: ICustomNode = customNodeFactory(CustomNodes.ControlFlowStorageCallNode);
|
||||
|
||||
controlFlowStorageCallNode1.initialize('controlFlowStorageName', key1, 1, 2);
|
||||
controlFlowStorageCallNode2.initialize('controlFlowStorageName', key2, 3, 4);
|
||||
|
||||
controlFlowStorage.set(key1, controlFlowStorageCallNode1);
|
||||
controlFlowStorage.set(key2, controlFlowStorageCallNode2);
|
||||
|
||||
assert.equal(
|
||||
controlFlowStorage.toString(),
|
||||
`${key1}: ${controlFlowStorageCallNode1.getCode()},${key2}: ${controlFlowStorageCallNode2.getCode()}`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user