mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added NodeMetadata class
This commit is contained in:
@@ -16,7 +16,7 @@ import { readFileAsString } from '../../../helpers/readFileAsString';
|
||||
|
||||
import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
|
||||
import { NodeAppender } from '../../../../src/node/NodeAppender';
|
||||
import { Nodes } from '../../../../src/node/Nodes';
|
||||
import { NodeFactory } from '../../../../src/node/NodeFactory';
|
||||
import { NodeUtils } from '../../../../src/node/NodeUtils';
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ const convertCodeToStructure: (fixturePath: string) => TStatement[] = (fixturePa
|
||||
* @return {ESTree.Program}
|
||||
*/
|
||||
const convertCodeToAst: (fixturePath: string) => ESTree.Program = (fixturePath) => {
|
||||
return Nodes.getProgramNode(convertCodeToStructure(fixturePath));
|
||||
return NodeFactory.programNode(convertCodeToStructure(fixturePath));
|
||||
};
|
||||
|
||||
describe('NodeAppender', () => {
|
||||
|
||||
@@ -2,8 +2,8 @@ import * as ESTree from 'estree';
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { Nodes } from '../../../../src/node/Nodes';
|
||||
import { NodeGuards } from '../../../../src/node/NodeGuards';
|
||||
import { NodeFactory } from '../../../../src/node/NodeFactory';
|
||||
import { NodeUtils } from '../../../../src/node/NodeUtils';
|
||||
|
||||
describe('NodeGuards', () => {
|
||||
@@ -11,8 +11,8 @@ describe('NodeGuards', () => {
|
||||
describe('truthful checks', () => {
|
||||
describe('Variant #1: block statement of function declaration', () => {
|
||||
const expectedResult: boolean = true;
|
||||
const node: ESTree.Node = Nodes.getBlockStatementNode();
|
||||
const parentNode: ESTree.FunctionDeclaration = Nodes.getFunctionDeclarationNode(
|
||||
const node: ESTree.Node = NodeFactory.blockStatementNode();
|
||||
const parentNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode(
|
||||
'foo',
|
||||
[],
|
||||
node
|
||||
@@ -32,8 +32,8 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #2: block statement of function expression', () => {
|
||||
const expectedResult: boolean = true;
|
||||
const node: ESTree.Node = Nodes.getBlockStatementNode();
|
||||
const parentNode: ESTree.FunctionExpression = Nodes.getFunctionExpressionNode(
|
||||
const node: ESTree.Node = NodeFactory.blockStatementNode();
|
||||
const parentNode: ESTree.FunctionExpression = NodeFactory.functionExpressionNode(
|
||||
[],
|
||||
node
|
||||
);
|
||||
@@ -54,20 +54,20 @@ describe('NodeGuards', () => {
|
||||
describe('false checks', () => {
|
||||
describe('Variant #1: switch-case node', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const node: ESTree.Node = Nodes.getSwitchCaseNode(
|
||||
Nodes.getLiteralNode(1),
|
||||
const node: ESTree.Node = NodeFactory.switchCaseNode(
|
||||
NodeFactory.literalNode(1),
|
||||
[]
|
||||
);
|
||||
const parentNode: ESTree.FunctionDeclaration = Nodes.getFunctionDeclarationNode(
|
||||
const parentNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode(
|
||||
'foo',
|
||||
[],
|
||||
Nodes.getBlockStatementNode([
|
||||
Nodes.getSwitchStatementNode(
|
||||
Nodes.getMemberExpressionNode(
|
||||
Nodes.getIdentifierNode('bar'),
|
||||
Nodes.getUpdateExpressionNode(
|
||||
NodeFactory.blockStatementNode([
|
||||
NodeFactory.switchStatementNode(
|
||||
NodeFactory.memberExpressionNode(
|
||||
NodeFactory.identifierNode('bar'),
|
||||
NodeFactory.updateExpressionNode(
|
||||
'++',
|
||||
Nodes.getIdentifierNode('baz')
|
||||
NodeFactory.identifierNode('baz')
|
||||
),
|
||||
true
|
||||
),
|
||||
@@ -90,14 +90,14 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #2: literal node', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const node: ESTree.Node = Nodes.getLiteralNode(1);
|
||||
const parentNode: ESTree.FunctionDeclaration = Nodes.getFunctionDeclarationNode(
|
||||
const node: ESTree.Node = NodeFactory.literalNode(1);
|
||||
const parentNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode(
|
||||
'foo',
|
||||
[],
|
||||
Nodes.getBlockStatementNode([
|
||||
Nodes.getExpressionStatementNode(
|
||||
Nodes.getCallExpressionNode(
|
||||
Nodes.getIdentifierNode('bar'),
|
||||
NodeFactory.blockStatementNode([
|
||||
NodeFactory.expressionStatementNode(
|
||||
NodeFactory.callExpressionNode(
|
||||
NodeFactory.identifierNode('bar'),
|
||||
[node]
|
||||
)
|
||||
)
|
||||
@@ -118,9 +118,9 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #3: block statement of if statement', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const node: ESTree.Node = Nodes.getBlockStatementNode();
|
||||
const parentNode: ESTree.IfStatement = Nodes.getIfStatementNode(
|
||||
Nodes.getIdentifierNode('foo'),
|
||||
const node: ESTree.Node = NodeFactory.blockStatementNode();
|
||||
const parentNode: ESTree.IfStatement = NodeFactory.ifStatementNode(
|
||||
NodeFactory.identifierNode('foo'),
|
||||
node
|
||||
);
|
||||
|
||||
@@ -142,7 +142,7 @@ describe('NodeGuards', () => {
|
||||
describe('truthful checks', () => {
|
||||
describe('Variant #1: program node', () => {
|
||||
const expectedResult: boolean = true;
|
||||
const node: ESTree.Node = Nodes.getProgramNode();
|
||||
const node: ESTree.Node = NodeFactory.programNode();
|
||||
|
||||
let result: boolean;
|
||||
|
||||
@@ -157,7 +157,7 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #2: block statement node', () => {
|
||||
const expectedResult: boolean = true;
|
||||
const node: ESTree.Node = Nodes.getBlockStatementNode();
|
||||
const node: ESTree.Node = NodeFactory.blockStatementNode();
|
||||
|
||||
let result: boolean;
|
||||
|
||||
@@ -172,8 +172,8 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #3: switch case node', () => {
|
||||
const expectedResult: boolean = true;
|
||||
const node: ESTree.Node = Nodes.getSwitchCaseNode(
|
||||
Nodes.getLiteralNode(1),
|
||||
const node: ESTree.Node = NodeFactory.switchCaseNode(
|
||||
NodeFactory.literalNode(1),
|
||||
[]
|
||||
);
|
||||
|
||||
@@ -192,7 +192,7 @@ describe('NodeGuards', () => {
|
||||
describe('false checks', () => {
|
||||
describe('Variant #1: literal node', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const node: ESTree.Node = Nodes.getLiteralNode(1);
|
||||
const node: ESTree.Node = NodeFactory.literalNode(1);
|
||||
|
||||
let result: boolean;
|
||||
|
||||
@@ -207,7 +207,7 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #2: identifier node', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const node: ESTree.Node = Nodes.getIdentifierNode('foo');
|
||||
const node: ESTree.Node = NodeFactory.identifierNode('foo');
|
||||
|
||||
let result: boolean;
|
||||
|
||||
@@ -222,9 +222,9 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #3: if-statement node', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const node: ESTree.Node = Nodes.getIfStatementNode(
|
||||
Nodes.getIdentifierNode('foo'),
|
||||
Nodes.getBlockStatementNode()
|
||||
const node: ESTree.Node = NodeFactory.ifStatementNode(
|
||||
NodeFactory.identifierNode('foo'),
|
||||
NodeFactory.blockStatementNode()
|
||||
);
|
||||
|
||||
let result: boolean;
|
||||
@@ -240,8 +240,8 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #4: switch-statement node', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const node: ESTree.Node = Nodes.getSwitchStatementNode(
|
||||
Nodes.getIdentifierNode('foo'),
|
||||
const node: ESTree.Node = NodeFactory.switchStatementNode(
|
||||
NodeFactory.identifierNode('foo'),
|
||||
[]
|
||||
);
|
||||
|
||||
@@ -262,11 +262,11 @@ describe('NodeGuards', () => {
|
||||
describe('truthful checks', () => {
|
||||
describe('Variant #1: parent node is function declaration node', () => {
|
||||
const expectedResult: boolean = true;
|
||||
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
|
||||
const parentNode: ESTree.Node = Nodes.getFunctionDeclarationNode(
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
|
||||
const parentNode: ESTree.Node = NodeFactory.functionDeclarationNode(
|
||||
'bar',
|
||||
[identifier],
|
||||
Nodes.getBlockStatementNode()
|
||||
NodeFactory.blockStatementNode()
|
||||
);
|
||||
|
||||
let result: boolean;
|
||||
@@ -283,10 +283,10 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #2: parent node is computed property node', () => {
|
||||
const expectedResult: boolean = true;
|
||||
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
|
||||
const parentNode: ESTree.Node = Nodes.getPropertyNode(
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
|
||||
const parentNode: ESTree.Node = NodeFactory.propertyNode(
|
||||
identifier,
|
||||
Nodes.getLiteralNode('bar'),
|
||||
NodeFactory.literalNode('bar'),
|
||||
true
|
||||
);
|
||||
|
||||
@@ -304,9 +304,9 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #4: parent node is computed member expression node', () => {
|
||||
const expectedResult: boolean = true;
|
||||
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
|
||||
const parentNode: ESTree.Node = Nodes.getMemberExpressionNode(
|
||||
Nodes.getIdentifierNode('bar'),
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
|
||||
const parentNode: ESTree.Node = NodeFactory.memberExpressionNode(
|
||||
NodeFactory.identifierNode('bar'),
|
||||
identifier,
|
||||
true
|
||||
);
|
||||
@@ -325,10 +325,10 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #4: parent node is computed method definition node', () => {
|
||||
const expectedResult: boolean = true;
|
||||
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
|
||||
const parentNode: ESTree.Node = Nodes.getMethodDefinitionNode(
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
|
||||
const parentNode: ESTree.Node = NodeFactory.methodDefinitionNode(
|
||||
identifier,
|
||||
Nodes.getFunctionExpressionNode([], Nodes.getBlockStatementNode()),
|
||||
NodeFactory.functionExpressionNode([], NodeFactory.blockStatementNode()),
|
||||
'method',
|
||||
true
|
||||
);
|
||||
@@ -349,10 +349,10 @@ describe('NodeGuards', () => {
|
||||
describe('false checks', () => {
|
||||
describe('Variant #1: node isn\'t an identifier', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const literal: ESTree.Literal = Nodes.getLiteralNode(1);
|
||||
const parentNode: ESTree.Node = Nodes.getExpressionStatementNode(
|
||||
Nodes.getCallExpressionNode(
|
||||
Nodes.getIdentifierNode('foo'),
|
||||
const literal: ESTree.Literal = NodeFactory.literalNode(1);
|
||||
const parentNode: ESTree.Node = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.callExpressionNode(
|
||||
NodeFactory.identifierNode('foo'),
|
||||
[literal]
|
||||
)
|
||||
);
|
||||
@@ -371,10 +371,10 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #2: parent node isn\'t computed property node', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
|
||||
const parentNode: ESTree.Node = Nodes.getPropertyNode(
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
|
||||
const parentNode: ESTree.Node = NodeFactory.propertyNode(
|
||||
identifier,
|
||||
Nodes.getLiteralNode('bar'),
|
||||
NodeFactory.literalNode('bar'),
|
||||
false
|
||||
);
|
||||
|
||||
@@ -392,9 +392,9 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #3: parent node isn\'t computed member expression node', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
|
||||
const parentNode: ESTree.Node = Nodes.getMemberExpressionNode(
|
||||
Nodes.getIdentifierNode('bar'),
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
|
||||
const parentNode: ESTree.Node = NodeFactory.memberExpressionNode(
|
||||
NodeFactory.identifierNode('bar'),
|
||||
identifier,
|
||||
false
|
||||
);
|
||||
@@ -413,10 +413,10 @@ describe('NodeGuards', () => {
|
||||
|
||||
describe('Variant #4: parent node isn\'t computed method definition node', () => {
|
||||
const expectedResult: boolean = false;
|
||||
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
|
||||
const parentNode: ESTree.Node = Nodes.getMethodDefinitionNode(
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
|
||||
const parentNode: ESTree.Node = NodeFactory.methodDefinitionNode(
|
||||
identifier,
|
||||
Nodes.getFunctionExpressionNode([], Nodes.getBlockStatementNode()),
|
||||
NodeFactory.functionExpressionNode([], NodeFactory.blockStatementNode()),
|
||||
'method',
|
||||
false
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { assert } from 'chai';
|
||||
|
||||
import { TStatement } from '../../../../src/types/node/TStatement';
|
||||
|
||||
import { Nodes } from '../../../../src/node/Nodes';
|
||||
import { NodeFactory } from '../../../../src/node/NodeFactory';
|
||||
import { NodeUtils } from '../../../../src/node/NodeUtils';
|
||||
|
||||
describe('NodeUtils', () => {
|
||||
@@ -13,10 +13,10 @@ describe('NodeUtils', () => {
|
||||
expectedLiteralNode: ESTree.Literal;
|
||||
|
||||
before(() => {
|
||||
literalNode = Nodes.getLiteralNode('value');
|
||||
literalNode = NodeFactory.literalNode('value');
|
||||
delete literalNode['x-verbatim-property'];
|
||||
|
||||
expectedLiteralNode = Nodes.getLiteralNode('value');
|
||||
expectedLiteralNode = NodeFactory.literalNode('value');
|
||||
|
||||
NodeUtils.addXVerbatimPropertyToLiterals(literalNode);
|
||||
});
|
||||
@@ -33,40 +33,40 @@ describe('NodeUtils', () => {
|
||||
|
||||
before(() => {
|
||||
// actual AST tree
|
||||
const expressionStatementNode1: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
const expressionStatementNode2: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
const expressionStatementNode1: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
const expressionStatementNode2: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
|
||||
const ifStatementBlockStatementNode1: ESTree.BlockStatement = Nodes.getBlockStatementNode([
|
||||
const ifStatementBlockStatementNode1: ESTree.BlockStatement = NodeFactory.blockStatementNode([
|
||||
expressionStatementNode1,
|
||||
expressionStatementNode2
|
||||
]);
|
||||
|
||||
const ifStatementNode1: ESTree.IfStatement = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
const ifStatementNode1: ESTree.IfStatement = NodeFactory.ifStatementNode(
|
||||
NodeFactory.literalNode(true),
|
||||
ifStatementBlockStatementNode1
|
||||
);
|
||||
|
||||
// expected AST tree
|
||||
const expressionStatementNode3: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
const expressionStatementNode4: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
const expressionStatementNode3: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
const expressionStatementNode4: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
|
||||
const ifStatementBlockStatementNode2: ESTree.BlockStatement = Nodes.getBlockStatementNode([
|
||||
const ifStatementBlockStatementNode2: ESTree.BlockStatement = NodeFactory.blockStatementNode([
|
||||
expressionStatementNode3,
|
||||
expressionStatementNode4
|
||||
]);
|
||||
|
||||
const ifStatementNode2: ESTree.IfStatement = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
const ifStatementNode2: ESTree.IfStatement = NodeFactory.ifStatementNode(
|
||||
NodeFactory.literalNode(true),
|
||||
ifStatementBlockStatementNode2
|
||||
);
|
||||
|
||||
programNode = NodeUtils.clone(
|
||||
Nodes.getProgramNode([
|
||||
NodeFactory.programNode([
|
||||
ifStatementNode1
|
||||
])
|
||||
);
|
||||
expectedProgramNode = NodeUtils.parentize(
|
||||
Nodes.getProgramNode([
|
||||
NodeFactory.programNode([
|
||||
ifStatementNode2
|
||||
])
|
||||
);
|
||||
@@ -83,34 +83,34 @@ describe('NodeUtils', () => {
|
||||
|
||||
before(() => {
|
||||
// actual AST tree
|
||||
const arrayExpressionNode: ESTree.ArrayExpression = Nodes.getArrayExpressionNode([
|
||||
Nodes.getLiteralNode(1),
|
||||
Nodes.getLiteralNode(2),
|
||||
const arrayExpressionNode: ESTree.ArrayExpression = NodeFactory.arrayExpressionNode([
|
||||
NodeFactory.literalNode(1),
|
||||
NodeFactory.literalNode(2),
|
||||
<any>null,
|
||||
Nodes.getLiteralNode(4)
|
||||
NodeFactory.literalNode(4)
|
||||
]);
|
||||
const expressionStatementNode: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(
|
||||
const expressionStatementNode: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(
|
||||
arrayExpressionNode
|
||||
);
|
||||
|
||||
// expected AST tree
|
||||
const expectedArrayExpressionNode: ESTree.ArrayExpression = Nodes.getArrayExpressionNode([
|
||||
Nodes.getLiteralNode(1),
|
||||
Nodes.getLiteralNode(2),
|
||||
const expectedArrayExpressionNode: ESTree.ArrayExpression = NodeFactory.arrayExpressionNode([
|
||||
NodeFactory.literalNode(1),
|
||||
NodeFactory.literalNode(2),
|
||||
<any>null,
|
||||
Nodes.getLiteralNode(4)
|
||||
NodeFactory.literalNode(4)
|
||||
]);
|
||||
const expectedExpressionStatementNode: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(
|
||||
const expectedExpressionStatementNode: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(
|
||||
expectedArrayExpressionNode
|
||||
);
|
||||
|
||||
programNode = NodeUtils.clone(
|
||||
Nodes.getProgramNode([
|
||||
NodeFactory.programNode([
|
||||
expressionStatementNode
|
||||
])
|
||||
);
|
||||
expectedProgramNode = NodeUtils.parentize(
|
||||
Nodes.getProgramNode([
|
||||
NodeFactory.programNode([
|
||||
expectedExpressionStatementNode
|
||||
])
|
||||
);
|
||||
@@ -131,13 +131,13 @@ describe('NodeUtils', () => {
|
||||
var abc = 'cde';
|
||||
`;
|
||||
|
||||
const identifierNode: ESTree.Identifier = Nodes.getIdentifierNode('abc');
|
||||
const literalNode: ESTree.Literal = Nodes.getLiteralNode('cde');
|
||||
const variableDeclaratorNode: ESTree.VariableDeclarator = Nodes.getVariableDeclaratorNode(identifierNode, literalNode);
|
||||
const variableDeclarationNode: ESTree.VariableDeclaration = Nodes.getVariableDeclarationNode([
|
||||
const identifierNode: ESTree.Identifier = NodeFactory.identifierNode('abc');
|
||||
const literalNode: ESTree.Literal = NodeFactory.literalNode('cde');
|
||||
const variableDeclaratorNode: ESTree.VariableDeclarator = NodeFactory.variableDeclaratorNode(identifierNode, literalNode);
|
||||
const variableDeclarationNode: ESTree.VariableDeclaration = NodeFactory.variableDeclarationNode([
|
||||
variableDeclaratorNode
|
||||
]);
|
||||
const programNode: ESTree.Program = Nodes.getProgramNode([
|
||||
const programNode: ESTree.Program = NodeFactory.programNode([
|
||||
variableDeclarationNode
|
||||
]);
|
||||
|
||||
@@ -162,11 +162,11 @@ describe('NodeUtils', () => {
|
||||
|
||||
before(() => {
|
||||
structure = [
|
||||
Nodes.getProgramNode([
|
||||
Nodes.getVariableDeclarationNode([
|
||||
Nodes.getVariableDeclaratorNode(
|
||||
Nodes.getIdentifierNode('abc'),
|
||||
Nodes.getLiteralNode('cde')
|
||||
NodeFactory.programNode([
|
||||
NodeFactory.variableDeclarationNode([
|
||||
NodeFactory.variableDeclaratorNode(
|
||||
NodeFactory.identifierNode('abc'),
|
||||
NodeFactory.literalNode('cde')
|
||||
)
|
||||
])
|
||||
])
|
||||
@@ -192,37 +192,37 @@ describe('NodeUtils', () => {
|
||||
programNode: ESTree.Program;
|
||||
|
||||
before(() => {
|
||||
expressionStatementNode1 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode2 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode3 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode1 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
expressionStatementNode2 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
expressionStatementNode3 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
|
||||
ifStatementBlockStatementNode2 = Nodes.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode2 = NodeFactory.blockStatementNode([
|
||||
expressionStatementNode2,
|
||||
expressionStatementNode3
|
||||
]);
|
||||
|
||||
ifStatementNode2 = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementNode2 = NodeFactory.ifStatementNode(
|
||||
NodeFactory.literalNode(true),
|
||||
ifStatementBlockStatementNode2
|
||||
);
|
||||
|
||||
ifStatementBlockStatementNode1 = Nodes.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([
|
||||
ifStatementNode2
|
||||
]);
|
||||
|
||||
ifStatementNode1 = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementNode1 = NodeFactory.ifStatementNode(
|
||||
NodeFactory.literalNode(true),
|
||||
ifStatementBlockStatementNode1
|
||||
);
|
||||
|
||||
functionDeclarationBlockStatementNode = Nodes.getBlockStatementNode([
|
||||
functionDeclarationBlockStatementNode = NodeFactory.blockStatementNode([
|
||||
expressionStatementNode1,
|
||||
ifStatementNode1
|
||||
]);
|
||||
|
||||
functionDeclarationNode = Nodes.getFunctionDeclarationNode('test', [], functionDeclarationBlockStatementNode);
|
||||
functionDeclarationNode = NodeFactory.functionDeclarationNode('test', [], functionDeclarationBlockStatementNode);
|
||||
|
||||
programNode = Nodes.getProgramNode([
|
||||
programNode = NodeFactory.programNode([
|
||||
functionDeclarationNode
|
||||
]);
|
||||
|
||||
@@ -301,17 +301,17 @@ describe('NodeUtils', () => {
|
||||
statementNode3: ESTree.Statement;
|
||||
|
||||
before(() => {
|
||||
statementNode1 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('a')
|
||||
statementNode1 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('a')
|
||||
);
|
||||
statementNode2 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('b')
|
||||
statementNode2 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('b')
|
||||
);
|
||||
statementNode3 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('c')
|
||||
statementNode3 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('c')
|
||||
);
|
||||
|
||||
const blockStatementNode: ESTree.BlockStatement = Nodes.getBlockStatementNode([
|
||||
const blockStatementNode: ESTree.BlockStatement = NodeFactory.blockStatementNode([
|
||||
statementNode1,
|
||||
statementNode2,
|
||||
statementNode3
|
||||
@@ -341,18 +341,18 @@ describe('NodeUtils', () => {
|
||||
statementNode3: ESTree.Statement;
|
||||
|
||||
before(() => {
|
||||
statementNode1 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('a')
|
||||
statementNode1 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('a')
|
||||
);
|
||||
statementNode2 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('b')
|
||||
statementNode2 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('b')
|
||||
);
|
||||
statementNode3 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('c')
|
||||
statementNode3 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('c')
|
||||
);
|
||||
|
||||
const switchCaseNode: ESTree.SwitchCase = Nodes.getSwitchCaseNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
const switchCaseNode: ESTree.SwitchCase = NodeFactory.switchCaseNode(
|
||||
NodeFactory.literalNode(true),
|
||||
[
|
||||
statementNode1,
|
||||
statementNode2,
|
||||
@@ -386,17 +386,17 @@ describe('NodeUtils', () => {
|
||||
statementNode3: ESTree.Statement;
|
||||
|
||||
before(() => {
|
||||
statementNode1 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('a')
|
||||
statementNode1 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('a')
|
||||
);
|
||||
statementNode2 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('b')
|
||||
statementNode2 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('b')
|
||||
);
|
||||
statementNode3 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('c')
|
||||
statementNode3 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('c')
|
||||
);
|
||||
|
||||
const blockStatementNode: ESTree.BlockStatement = Nodes.getBlockStatementNode([
|
||||
const blockStatementNode: ESTree.BlockStatement = NodeFactory.blockStatementNode([
|
||||
statementNode1,
|
||||
statementNode2,
|
||||
statementNode3
|
||||
@@ -426,18 +426,18 @@ describe('NodeUtils', () => {
|
||||
statementNode3: ESTree.Statement;
|
||||
|
||||
before(() => {
|
||||
statementNode1 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('a')
|
||||
statementNode1 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('a')
|
||||
);
|
||||
statementNode2 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('b')
|
||||
statementNode2 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('b')
|
||||
);
|
||||
statementNode3 = Nodes.getExpressionStatementNode(
|
||||
Nodes.getIdentifierNode('c')
|
||||
statementNode3 = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('c')
|
||||
);
|
||||
|
||||
const switchCaseNode: ESTree.SwitchCase = Nodes.getSwitchCaseNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
const switchCaseNode: ESTree.SwitchCase = NodeFactory.switchCaseNode(
|
||||
NodeFactory.literalNode(true),
|
||||
[
|
||||
statementNode1,
|
||||
statementNode2,
|
||||
@@ -481,59 +481,59 @@ describe('NodeUtils', () => {
|
||||
programNode: ESTree.Program;
|
||||
|
||||
before(() => {
|
||||
expressionStatementNode1 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode2 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode3 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode1 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
expressionStatementNode2 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
expressionStatementNode3 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
|
||||
ifStatementBlockStatementNode3 = Nodes.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode3 = NodeFactory.blockStatementNode([
|
||||
expressionStatementNode2,
|
||||
expressionStatementNode3
|
||||
]);
|
||||
|
||||
ifStatementNode3 = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementNode3 = NodeFactory.ifStatementNode(
|
||||
NodeFactory.literalNode(true),
|
||||
ifStatementBlockStatementNode3
|
||||
);
|
||||
|
||||
ifStatementBlockStatementNode2 = Nodes.getBlockStatementNode();
|
||||
ifStatementBlockStatementNode2 = NodeFactory.blockStatementNode();
|
||||
|
||||
ifStatementBlockStatementNode1 = Nodes.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([
|
||||
ifStatementNode3
|
||||
]);
|
||||
|
||||
ifStatementNode2 = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementNode2 = NodeFactory.ifStatementNode(
|
||||
NodeFactory.literalNode(true),
|
||||
ifStatementBlockStatementNode2
|
||||
);
|
||||
|
||||
ifStatementNode1 = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementNode1 = NodeFactory.ifStatementNode(
|
||||
NodeFactory.literalNode(true),
|
||||
ifStatementBlockStatementNode1
|
||||
);
|
||||
|
||||
switchCaseNode = Nodes.getSwitchCaseNode(
|
||||
Nodes.getLiteralNode(1),
|
||||
switchCaseNode = NodeFactory.switchCaseNode(
|
||||
NodeFactory.literalNode(1),
|
||||
[
|
||||
ifStatementNode2
|
||||
]
|
||||
);
|
||||
|
||||
switchStatementNode = Nodes.getSwitchStatementNode(
|
||||
Nodes.getLiteralNode(1),
|
||||
switchStatementNode = NodeFactory.switchStatementNode(
|
||||
NodeFactory.literalNode(1),
|
||||
[
|
||||
switchCaseNode
|
||||
]
|
||||
);
|
||||
|
||||
functionDeclarationBlockStatementNode = Nodes.getBlockStatementNode([
|
||||
functionDeclarationBlockStatementNode = NodeFactory.blockStatementNode([
|
||||
expressionStatementNode1,
|
||||
ifStatementNode1,
|
||||
switchStatementNode
|
||||
]);
|
||||
|
||||
functionDeclarationNode = Nodes.getFunctionDeclarationNode('test', [], functionDeclarationBlockStatementNode);
|
||||
functionDeclarationNode = NodeFactory.functionDeclarationNode('test', [], functionDeclarationBlockStatementNode);
|
||||
|
||||
programNode = Nodes.getProgramNode([
|
||||
programNode = NodeFactory.programNode([
|
||||
functionDeclarationNode
|
||||
]);
|
||||
|
||||
@@ -610,11 +610,11 @@ describe('NodeUtils', () => {
|
||||
unaryExpressionArgumentNode: ESTree.Node;
|
||||
|
||||
before(() => {
|
||||
const literalNode: ESTree.Literal = Nodes.getLiteralNode('test');
|
||||
const unaryExpressionNode2: ESTree.UnaryExpression = Nodes.getUnaryExpressionNode('!', literalNode);
|
||||
const unaryExpressionNode1: ESTree.UnaryExpression = Nodes.getUnaryExpressionNode('!', unaryExpressionNode2);
|
||||
const expressionStatementNode: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(unaryExpressionNode1);
|
||||
const programNode: ESTree.Program = Nodes.getProgramNode([
|
||||
const literalNode: ESTree.Literal = NodeFactory.literalNode('test');
|
||||
const unaryExpressionNode2: ESTree.UnaryExpression = NodeFactory.unaryExpressionNode('!', literalNode);
|
||||
const unaryExpressionNode1: ESTree.UnaryExpression = NodeFactory.unaryExpressionNode('!', unaryExpressionNode2);
|
||||
const expressionStatementNode: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(unaryExpressionNode1);
|
||||
const programNode: ESTree.Program = NodeFactory.programNode([
|
||||
expressionStatementNode
|
||||
]);
|
||||
|
||||
@@ -641,23 +641,23 @@ describe('NodeUtils', () => {
|
||||
programNode: ESTree.Program;
|
||||
|
||||
beforeEach(() => {
|
||||
expressionStatementNode1 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode2 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
expressionStatementNode1 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
expressionStatementNode2 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier'));
|
||||
|
||||
ifStatementBlockStatementNode = Nodes.getBlockStatementNode([
|
||||
ifStatementBlockStatementNode = NodeFactory.blockStatementNode([
|
||||
expressionStatementNode1,
|
||||
expressionStatementNode2
|
||||
]);
|
||||
|
||||
ifStatementNode = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementNode = NodeFactory.ifStatementNode(
|
||||
NodeFactory.literalNode(true),
|
||||
ifStatementBlockStatementNode
|
||||
);
|
||||
});
|
||||
|
||||
describe('Variant #1: parentize AST-tree with `ProgramNode` as root node', () => {
|
||||
beforeEach(() => {
|
||||
programNode = Nodes.getProgramNode([
|
||||
programNode = NodeFactory.programNode([
|
||||
ifStatementNode
|
||||
]);
|
||||
|
||||
@@ -710,8 +710,8 @@ describe('NodeUtils', () => {
|
||||
|
||||
describe('parentizeNode <T extends ESTree.Node = ESTree.Program> (node: T, parentNode: ESTree.Node): T', () => {
|
||||
describe('Variant #1: node with parent node', () => {
|
||||
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
|
||||
const breakStatement: ESTree.BreakStatement = Nodes.getBreakStatement(identifier);
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
|
||||
const breakStatement: ESTree.BreakStatement = NodeFactory.breakStatement(identifier);
|
||||
|
||||
const expectedResult: ESTree.Identifier = NodeUtils.clone(identifier);
|
||||
|
||||
@@ -729,7 +729,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
describe('Variant #2: node without parent node', () => {
|
||||
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('Foo');
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('Foo');
|
||||
const expectedResult: ESTree.Identifier = NodeUtils.clone(identifier);
|
||||
|
||||
let result: ESTree.Identifier;
|
||||
|
||||
Reference in New Issue
Block a user