More type-safe way to initialize custom nodes

This commit is contained in:
sanex3339
2020-01-09 02:59:59 +03:00
parent 7ecaa1dfdb
commit bb85924de5
21 changed files with 117 additions and 60 deletions
+5 -3
View File
@@ -14,7 +14,9 @@ import { GlobalVariableTemplate1 } from '../templates/GlobalVariableTemplate1';
import { GlobalVariableTemplate2 } from '../templates/GlobalVariableTemplate2';
@injectable()
export abstract class AbstractCustomNode implements ICustomNode {
export abstract class AbstractCustomNode <
TInitialData extends any[] = any[]
> implements ICustomNode <TInitialData> {
/**
* @type {string[]}
*/
@@ -68,9 +70,9 @@ export abstract class AbstractCustomNode implements ICustomNode {
}
/**
* @param {unknown[]} args
* @param {TInitialData} args
*/
public abstract initialize (...args: unknown[]): void;
public abstract initialize (...args: TInitialData): void;
/**
* @returns {TStatement[]}
@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
import { TInitialData } from '../../../types/TInitialData';
import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -16,7 +17,9 @@ import { CustomNode } from '../../../enums/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { ConsoleOutputDisableExpressionNode } from '../ConsoleOutputDisableExpressionNode';
import { NodeAppender } from '../../../node/NodeAppender';
import { NodeCallsControllerFunctionNode } from '../../node-calls-controller-nodes/NodeCallsControllerFunctionNode';
@injectable()
export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
@@ -90,8 +93,10 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
const consoleOutputDisableExpressionNode: ICustomNode = this.customNodeFactory(CustomNode.ConsoleOutputDisableExpressionNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
const consoleOutputDisableExpressionNode: ICustomNode<TInitialData<ConsoleOutputDisableExpressionNode>> =
this.customNodeFactory(CustomNode.ConsoleOutputDisableExpressionNode);
const nodeCallsControllerFunctionNode: ICustomNode<TInitialData<NodeCallsControllerFunctionNode>> =
this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
consoleOutputDisableExpressionNode.initialize(callsControllerFunctionName);
nodeCallsControllerFunctionNode.initialize(this.appendEvent, callsControllerFunctionName);
@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
import { TInitialData } from '../../../types/TInitialData';
import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -16,7 +17,11 @@ import { CustomNode } from '../../../enums/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { DebugProtectionFunctionNode } from '../DebugProtectionFunctionNode';
import { DebugProtectionFunctionCallNode } from '../DebugProtectionFunctionCallNode';
import { DebugProtectionFunctionIntervalNode } from '../DebugProtectionFunctionIntervalNode';
import { NodeAppender } from '../../../node/NodeAppender';
import { NodeCallsControllerFunctionNode } from '../../node-calls-controller-nodes/NodeCallsControllerFunctionNode';
import { NodeGuards } from '../../../node/NodeGuards';
@injectable()
@@ -107,10 +112,14 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
const debugProtectionFunctionName: string = this.identifierNamesGenerator.generate();
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
const debugProtectionFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionNode);
const debugProtectionFunctionCallNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionCallNode);
const debugProtectionFunctionIntervalNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionIntervalNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
const debugProtectionFunctionNode: ICustomNode<TInitialData<DebugProtectionFunctionNode>> =
this.customNodeFactory(CustomNode.DebugProtectionFunctionNode);
const debugProtectionFunctionCallNode: ICustomNode<TInitialData<DebugProtectionFunctionCallNode>> =
this.customNodeFactory(CustomNode.DebugProtectionFunctionCallNode);
const debugProtectionFunctionIntervalNode: ICustomNode<TInitialData<DebugProtectionFunctionIntervalNode>> =
this.customNodeFactory(CustomNode.DebugProtectionFunctionIntervalNode);
const nodeCallsControllerFunctionNode: ICustomNode<TInitialData<NodeCallsControllerFunctionNode>> =
this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
debugProtectionFunctionNode.initialize(debugProtectionFunctionName);
debugProtectionFunctionCallNode.initialize(debugProtectionFunctionName, callsControllerFunctionName);
@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
import { TInitialData } from '../../../types/TInitialData';
import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -16,7 +17,9 @@ import { CustomNode } from '../../../enums/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { DomainLockNode } from '../DomainLockNode';
import { NodeAppender } from '../../../node/NodeAppender';
import { NodeCallsControllerFunctionNode } from '../../node-calls-controller-nodes/NodeCallsControllerFunctionNode';
@injectable()
export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
@@ -90,8 +93,10 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
const domainLockNode: ICustomNode = this.customNodeFactory(CustomNode.DomainLockNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
const domainLockNode: ICustomNode<TInitialData<DomainLockNode>> =
this.customNodeFactory(CustomNode.DomainLockNode);
const nodeCallsControllerFunctionNode: ICustomNode<TInitialData<NodeCallsControllerFunctionNode>> =
this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
domainLockNode.initialize(callsControllerFunctionName);
nodeCallsControllerFunctionNode.initialize(this.appendEvent, callsControllerFunctionName);
@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
import { TInitialData } from '../../../types/TInitialData';
import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -17,6 +18,8 @@ import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { NodeAppender } from '../../../node/NodeAppender';
import { NodeCallsControllerFunctionNode } from '../../node-calls-controller-nodes/NodeCallsControllerFunctionNode';
import { SelfDefendingUnicodeNode } from '../SelfDefendingUnicodeNode';
@injectable()
export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
@@ -90,8 +93,10 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
const selfDefendingUnicodeNode: ICustomNode = this.customNodeFactory(CustomNode.SelfDefendingUnicodeNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
const selfDefendingUnicodeNode: ICustomNode<TInitialData<SelfDefendingUnicodeNode>> =
this.customNodeFactory(CustomNode.SelfDefendingUnicodeNode);
const nodeCallsControllerFunctionNode: ICustomNode<TInitialData<NodeCallsControllerFunctionNode>> =
this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
selfDefendingUnicodeNode.initialize(callsControllerFunctionName);
nodeCallsControllerFunctionNode.initialize(this.appendEvent, callsControllerFunctionName);
@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
import { TInitialData } from '../../../types/TInitialData';
import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
import { TStringArrayStorage } from '../../../types/storages/TStringArrayStorage';
@@ -18,6 +19,9 @@ import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { NodeAppender } from '../../../node/NodeAppender';
import { StringArrayNode } from '../StringArrayNode';
import { StringArrayCallsWrapper } from '../StringArrayCallsWrapper';
import { StringArrayRotateFunctionNode } from '../StringArrayRotateFunctionNode';
@injectable()
export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
@@ -95,9 +99,12 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
return;
}
const stringArrayNode: ICustomNode = this.customNodeFactory(CustomNode.StringArrayNode);
const stringArrayCallsWrapper: ICustomNode = this.customNodeFactory(CustomNode.StringArrayCallsWrapper);
const stringArrayRotateFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.StringArrayRotateFunctionNode);
const stringArrayNode: ICustomNode<TInitialData<StringArrayNode>> =
this.customNodeFactory(CustomNode.StringArrayNode);
const stringArrayCallsWrapper: ICustomNode<TInitialData<StringArrayCallsWrapper>> =
this.customNodeFactory(CustomNode.StringArrayCallsWrapper);
const stringArrayRotateFunctionNode: ICustomNode<TInitialData<StringArrayRotateFunctionNode>> =
this.customNodeFactory(CustomNode.StringArrayRotateFunctionNode);
const stringArrayStorageId: string = this.stringArrayStorage.getStorageId();
+3 -1
View File
@@ -2,7 +2,9 @@ import { TStatement } from '../../types/node/TStatement';
import { IInitializable } from '../IInitializable';
export interface ICustomNode extends IInitializable<any[]> {
export interface ICustomNode <
TInitialData extends any[] = any[]
> extends IInitializable<TInitialData> {
/**
* @returns ESTree.Node[]
*/
@@ -5,6 +5,7 @@ import * as estraverse from 'estraverse';
import * as ESTree from 'estree';
import { TControlFlowCustomNodeFactory } from '../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
import { TInitialData } from '../../types/TInitialData';
import { TStatement } from '../../types/node/TStatement';
import { IArrayUtils } from '../../interfaces/utils/IArrayUtils';
@@ -17,6 +18,7 @@ import { ControlFlowCustomNode } from '../../enums/custom-nodes/ControlFlowCusto
import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { BlockStatementControlFlowFlatteningNode } from '../../custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode';
import { NodeGuards } from '../../node/NodeGuards';
import { NodeUtils } from '../../node/NodeUtils';
@@ -131,9 +133,8 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme
const originalKeys: number[] = this.arrayUtils.createWithRange(blockStatementBody.length);
const shuffledKeys: number[] = this.arrayUtils.shuffle(originalKeys);
const originalKeysIndexesInShuffledArray: number[] = originalKeys.map((key: number) => shuffledKeys.indexOf(key));
const blockStatementControlFlowFlatteningCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.BlockStatementControlFlowFlatteningNode
);
const blockStatementControlFlowFlatteningCustomNode: ICustomNode<TInitialData<BlockStatementControlFlowFlatteningNode>> =
this.controlFlowCustomNodeFactory(ControlFlowCustomNode.BlockStatementControlFlowFlatteningNode);
blockStatementControlFlowFlatteningCustomNode.initialize(
blockStatementBody,
@@ -8,6 +8,7 @@ import { TControlFlowCustomNodeFactory } from '../../types/container/custom-node
import { TControlFlowReplacerFactory } from '../../types/container/node-transformers/TControlFlowReplacerFactory';
import { TControlFlowStorage } from '../../types/storages/TControlFlowStorage';
import { TControlFlowStorageFactory } from '../../types/container/node-transformers/TControlFlowStorageFactory';
import { TInitialData } from '../../types/TInitialData';
import { TNodeWithStatements } from '../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
@@ -21,6 +22,7 @@ import { NodeType } from '../../enums/node/NodeType';
import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { ControlFlowStorageNode } from '../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode';
import { NodeAppender } from '../../node/NodeAppender';
import { NodeGuards } from '../../node/NodeGuards';
import { NodeMetadata } from '../../node/NodeMetadata';
@@ -151,9 +153,8 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
return functionNode;
}
const controlFlowStorageCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.ControlFlowStorageNode
);
const controlFlowStorageCustomNode: ICustomNode<TInitialData<ControlFlowStorageNode>> =
this.controlFlowCustomNodeFactory(ControlFlowCustomNode.ControlFlowStorageNode);
controlFlowStorageCustomNode.initialize(controlFlowStorage);
NodeAppender.prepend(hostNode, controlFlowStorageCustomNode.getNode());
@@ -5,6 +5,7 @@ import * as ESTree from 'estree';
import { TControlFlowCustomNodeFactory } from '../../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage';
import { TInitialData } from '../../../types/TInitialData';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
@@ -12,6 +13,7 @@ import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCustomNode';
import { BinaryExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode';
import { ExpressionWithOperatorControlFlowReplacer } from './ExpressionWithOperatorControlFlowReplacer';
@injectable()
@@ -46,17 +48,16 @@ export class BinaryExpressionControlFlowReplacer extends ExpressionWithOperatorC
parentNode: ESTree.Node,
controlFlowStorage: TControlFlowStorage
): ESTree.Node {
const replacerId: string = binaryExpressionNode.operator;
const binaryExpressionFunctionCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.BinaryExpressionFunctionNode
);
const operator: ESTree.BinaryOperator = binaryExpressionNode.operator;
const binaryExpressionFunctionCustomNode: ICustomNode<TInitialData<BinaryExpressionFunctionNode>> =
this.controlFlowCustomNodeFactory(ControlFlowCustomNode.BinaryExpressionFunctionNode);
binaryExpressionFunctionCustomNode.initialize(replacerId);
binaryExpressionFunctionCustomNode.initialize(operator);
const storageKey: string = this.insertCustomNodeToControlFlowStorage(
binaryExpressionFunctionCustomNode,
controlFlowStorage,
replacerId,
operator,
BinaryExpressionControlFlowReplacer.usingExistingIdentifierChance
);
@@ -5,6 +5,7 @@ import * as ESTree from 'estree';
import { TControlFlowCustomNodeFactory } from '../../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage';
import { TInitialData } from '../../../types/TInitialData';
import { TStatement } from '../../../types/node/TStatement';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -14,6 +15,8 @@ import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCustomNode';
import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer';
import { CallExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode';
import { CallExpressionControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode';
import { NodeGuards } from '../../../node/NodeGuards';
@injectable()
@@ -55,9 +58,8 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac
}
const replacerId: string = String(callExpressionNode.arguments.length);
const callExpressionFunctionCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.CallExpressionFunctionNode
);
const callExpressionFunctionCustomNode: ICustomNode<TInitialData<CallExpressionFunctionNode>> =
this.controlFlowCustomNodeFactory(ControlFlowCustomNode.CallExpressionFunctionNode);
const expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[] = callExpressionNode.arguments;
callExpressionFunctionCustomNode.initialize(expressionArguments);
@@ -90,9 +92,8 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac
callee: ESTree.Expression,
expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[]
): ESTree.Node {
const controlFlowStorageCallCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.CallExpressionControlFlowStorageCallNode
);
const controlFlowStorageCallCustomNode: ICustomNode<TInitialData<CallExpressionControlFlowStorageCallNode>> =
this.controlFlowCustomNodeFactory(ControlFlowCustomNode.CallExpressionControlFlowStorageCallNode);
controlFlowStorageCallCustomNode.initialize(controlFlowStorageId, storageKey, callee, expressionArguments);
@@ -4,6 +4,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
import * as ESTree from 'estree';
import { TControlFlowCustomNodeFactory } from '../../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
import { TInitialData } from '../../../types/TInitialData';
import { TStatement } from '../../../types/node/TStatement';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -13,6 +14,7 @@ import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCustomNode';
import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer';
import { ExpressionWithOperatorControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode';
import { NodeGuards } from '../../../node/NodeGuards';
@injectable()
@@ -44,9 +46,8 @@ export abstract class ExpressionWithOperatorControlFlowReplacer extends Abstract
leftExpression: ESTree.Expression,
rightExpression: ESTree.Expression
): ESTree.Node {
const controlFlowStorageCallCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.ExpressionWithOperatorControlFlowStorageCallNode
);
const controlFlowStorageCallCustomNode: ICustomNode<TInitialData<ExpressionWithOperatorControlFlowStorageCallNode>> =
this.controlFlowCustomNodeFactory(ControlFlowCustomNode.ExpressionWithOperatorControlFlowStorageCallNode);
controlFlowStorageCallCustomNode.initialize(controlFlowStorageId, storageKey, leftExpression, rightExpression);
@@ -5,6 +5,7 @@ import * as ESTree from 'estree';
import { TControlFlowCustomNodeFactory } from '../../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage';
import { TInitialData } from '../../../types/TInitialData';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
@@ -13,6 +14,7 @@ import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCustomNode';
import { ExpressionWithOperatorControlFlowReplacer } from './ExpressionWithOperatorControlFlowReplacer';
import { LogicalExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode';
import { NodeGuards } from '../../../node/NodeGuards';
import { NodeUtils } from '../../../node/NodeUtils';
@@ -52,17 +54,16 @@ export class LogicalExpressionControlFlowReplacer extends ExpressionWithOperator
return logicalExpressionNode;
}
const replacerId: string = logicalExpressionNode.operator;
const logicalExpressionFunctionCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.LogicalExpressionFunctionNode
);
const operator: ESTree.LogicalOperator = logicalExpressionNode.operator;
const logicalExpressionFunctionCustomNode: ICustomNode<TInitialData<LogicalExpressionFunctionNode>> =
this.controlFlowCustomNodeFactory(ControlFlowCustomNode.LogicalExpressionFunctionNode);
logicalExpressionFunctionCustomNode.initialize(replacerId);
logicalExpressionFunctionCustomNode.initialize(operator);
const storageKey: string = this.insertCustomNodeToControlFlowStorage(
logicalExpressionFunctionCustomNode,
controlFlowStorage,
replacerId,
operator,
LogicalExpressionControlFlowReplacer.usingExistingIdentifierChance
);
@@ -5,6 +5,7 @@ import * as ESTree from 'estree';
import { TControlFlowCustomNodeFactory } from '../../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage';
import { TInitialData } from '../../../types/TInitialData';
import { TStatement } from '../../../types/node/TStatement';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -15,6 +16,8 @@ import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCu
import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer';
import { NodeGuards } from '../../../node/NodeGuards';
import { StringLiteralControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode';
import { StringLiteralNode } from '../../../custom-nodes/control-flow-flattening-nodes/StringLiteralNode';
@injectable()
export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplacer {
@@ -57,9 +60,8 @@ export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplace
}
const replacerId: string = String(literalNode.value);
const literalFunctionCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.StringLiteralNode
);
const literalFunctionCustomNode: ICustomNode<TInitialData<StringLiteralNode>> =
this.controlFlowCustomNodeFactory(ControlFlowCustomNode.StringLiteralNode);
literalFunctionCustomNode.initialize(literalNode.value);
@@ -82,9 +84,8 @@ export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplace
controlFlowStorageId: string,
storageKey: string
): ESTree.Node {
const controlFlowStorageCallCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.StringLiteralControlFlowStorageCallNode
);
const controlFlowStorageCallCustomNode: ICustomNode<TInitialData<StringLiteralControlFlowStorageCallNode>> =
this.controlFlowCustomNodeFactory(ControlFlowCustomNode.StringLiteralControlFlowStorageCallNode);
controlFlowStorageCallCustomNode.initialize(controlFlowStorageId, storageKey);
@@ -8,12 +8,14 @@ import { TObjectExpressionKeysTransformerCustomNodeFactory } from '../../../type
import { TStatement } from '../../../types/node/TStatement';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { TInitialData } from '../../../types/TInitialData';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { ObjectExpressionKeysTransformerCustomNode } from '../../../enums/custom-nodes/ObjectExpressionKeysTransformerCustomNode';
import { AbstractPropertiesExtractor } from './AbstractPropertiesExtractor';
import { BasePropertiesExtractorObjectExpressionHostNode } from '../../../custom-nodes/object-expression-keys-transformer-nodes/BasePropertiesExtractorObjectExpressionHostNode';
import { NodeAppender } from '../../../node/NodeAppender';
import { NodeGuards } from '../../../node/NodeGuards';
@@ -92,9 +94,10 @@ export class BasePropertiesExtractor extends AbstractPropertiesExtractor {
* @returns {VariableDeclaration}
*/
private getObjectExpressionHostNode (): ESTree.VariableDeclaration {
const objectExpressionHostCustomNode: ICustomNode = this.objectExpressionKeysTransformerCustomNodeFactory(
ObjectExpressionKeysTransformerCustomNode.BasePropertiesExtractorObjectExpressionHostNode
);
const objectExpressionHostCustomNode: ICustomNode<TInitialData<BasePropertiesExtractorObjectExpressionHostNode>> =
this.objectExpressionKeysTransformerCustomNodeFactory(
ObjectExpressionKeysTransformerCustomNode.BasePropertiesExtractorObjectExpressionHostNode
);
objectExpressionHostCustomNode.initialize();
@@ -5,6 +5,7 @@ import * as estraverse from 'estraverse';
import * as ESTree from 'estree';
import { TDeadNodeInjectionCustomNodeFactory } from '../../types/container/custom-nodes/TDeadNodeInjectionCustomNodeFactory';
import { TInitialData } from '../../types/TInitialData';
import { TNodeWithStatements } from '../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
@@ -19,6 +20,7 @@ import { NodeType } from '../../enums/node/NodeType';
import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { BlockStatementDeadCodeInjectionNode } from '../../custom-nodes/dead-code-injection-nodes/BlockStatementDeadCodeInjectionNode';
import { NodeFactory } from '../../node/NodeFactory';
import { NodeGuards } from '../../node/NodeGuards';
import { NodeStatementUtils } from '../../node/NodeStatementUtils';
@@ -389,9 +391,8 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
*/
this.deadCodeInjectionRootAstHostNodeSet.add(deadCodeInjectionRootAstHostNode);
const blockStatementDeadCodeInjectionCustomNode: ICustomNode = this.deadCodeInjectionCustomNodeFactory(
DeadCodeInjectionCustomNode.BlockStatementDeadCodeInjectionNode
);
const blockStatementDeadCodeInjectionCustomNode: ICustomNode<TInitialData<BlockStatementDeadCodeInjectionNode>> =
this.deadCodeInjectionCustomNodeFactory(DeadCodeInjectionCustomNode.BlockStatementDeadCodeInjectionNode);
blockStatementDeadCodeInjectionCustomNode.initialize(blockStatementNode, deadCodeInjectionRootAstHostNode);
+3
View File
@@ -0,0 +1,3 @@
import { IInitializable } from '../interfaces/IInitializable';
export type TInitialData <TClass extends IInitializable> = Parameters<TClass['initialize']>;
@@ -2,4 +2,6 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCustomNode';
export type TControlFlowCustomNodeFactory = (controlFlowCustomNodeName: ControlFlowCustomNode) => ICustomNode;
export type TControlFlowCustomNodeFactory = <
TInitialData extends any[] = any[]
> (controlFlowCustomNodeName: ControlFlowCustomNode) => ICustomNode<TInitialData>;
+3 -1
View File
@@ -2,4 +2,6 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { CustomNode } from '../../../enums/custom-nodes/CustomNode';
export type TCustomNodeFactory = (customNodeName: CustomNode) => ICustomNode;
export type TCustomNodeFactory = <
TInitialData extends any[] = any[]
> (customNodeName: CustomNode) => ICustomNode<TInitialData>;
@@ -2,4 +2,6 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { DeadCodeInjectionCustomNode } from '../../../enums/custom-nodes/DeadCodeInjectionCustomNode';
export type TDeadNodeInjectionCustomNodeFactory = (deadCodeInjectionCustomNodeName: DeadCodeInjectionCustomNode) => ICustomNode;
export type TDeadNodeInjectionCustomNodeFactory = <
TInitialData extends any[] = any[]
> (deadCodeInjectionCustomNodeName: DeadCodeInjectionCustomNode) => ICustomNode <TInitialData>;
@@ -2,4 +2,6 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { ObjectExpressionKeysTransformerCustomNode } from '../../../enums/custom-nodes/ObjectExpressionKeysTransformerCustomNode';
export type TObjectExpressionKeysTransformerCustomNodeFactory = (objectExpressionKeysTransformerNodeName: ObjectExpressionKeysTransformerCustomNode) => ICustomNode;
export type TObjectExpressionKeysTransformerCustomNodeFactory = <
TInitialData extends any[] = any[]
> (objectExpressionKeysTransformerNodeName: ObjectExpressionKeysTransformerCustomNode) => ICustomNode <TInitialData>;