فهرست منبع

Shifted indexes of string array wrappers #3: added ability to generate a negative shifted index

sanex 4 سال پیش
والد
کامیت
33441ebf36

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/index.browser.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/index.cli.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/index.js


+ 77 - 0
src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts

@@ -0,0 +1,77 @@
+import { inject, injectable, } from 'inversify';
+import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
+
+import * as ESTree from 'estree';
+
+import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
+
+import { ICustomCodeHelperFormatter } from '../../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
+import { IOptions } from '../../interfaces/options/IOptions';
+import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
+
+import { AbstractCustomNode } from '../AbstractCustomNode';
+import { NodeFactory } from '../../node/NodeFactory';
+import { NodeMetadata } from '../../node/NodeMetadata';
+import { NodeUtils } from '../../node/NodeUtils';
+import { NumberUtils } from '../../utils/NumberUtils';
+
+@injectable()
+export abstract class AbstractStringArrayCallNode extends AbstractCustomNode {
+    /**
+     * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
+     * @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
+     * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
+     */
+    protected constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
+            identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
+        @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter,
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
+    ) {
+        super(
+            identifierNamesGeneratorFactory,
+            customCodeHelperFormatter,
+            randomGenerator,
+            options
+        );
+    }
+
+    /**
+     * @param {number} index
+     * @returns {Expression}
+     */
+    protected getHexadecimalNode (index: number): ESTree.Expression {
+        const isPositive: boolean = index >= 0;
+        const normalizedIndex: number = Math.abs(index);
+
+        const hexadecimalIndex: string = NumberUtils.toHex(normalizedIndex);
+        const hexadecimalLiteralNode: ESTree.Literal = NodeFactory.literalNode(hexadecimalIndex);
+
+        NodeMetadata.set(hexadecimalLiteralNode, { replacedLiteral: true });
+
+        const hexadecimalNode: ESTree.Expression = isPositive
+            ? hexadecimalLiteralNode
+            : NodeFactory.unaryExpressionNode(
+                '-',
+                hexadecimalLiteralNode
+            );
+
+        NodeUtils.parentizeAst(hexadecimalNode);
+        
+        return hexadecimalNode;
+    }
+
+    /**
+     * @param {string} decodeKey
+     * @returns {Literal}
+     */
+    protected getRc4KeyLiteralNode (decodeKey: string): ESTree.Literal {
+        const rc4KeyLiteralNode: ESTree.Literal = NodeFactory.literalNode(decodeKey);
+
+        NodeMetadata.set(rc4KeyLiteralNode, { replacedLiteral: true });
+
+        return rc4KeyLiteralNode;
+    }
+}

+ 5 - 32
src/custom-nodes/string-array-nodes/StringArrayCallNode.ts

@@ -12,14 +12,12 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { AbstractCustomNode } from '../AbstractCustomNode';
+import { AbstractStringArrayCallNode } from './AbstractStringArrayCallNode';
 import { NodeFactory } from '../../node/NodeFactory';
-import { NodeMetadata } from '../../node/NodeMetadata';
 import { NodeUtils } from '../../node/NodeUtils';
-import { NumberUtils } from '../../utils/NumberUtils';
 
 @injectable()
-export class StringArrayCallNode extends AbstractCustomNode {
+export class StringArrayCallNode extends AbstractStringArrayCallNode {
     /**
      * @type {string | null}
      */
@@ -60,31 +58,6 @@ export class StringArrayCallNode extends AbstractCustomNode {
         );
     }
 
-    /**
-     * @param {string} index
-     * @returns {Literal}
-     */
-    public static getHexadecimalLiteralNode (index: number): ESTree.Literal {
-        const hexadecimalIndex: string = NumberUtils.toHex(index);
-        const hexadecimalLiteralNode: ESTree.Literal = NodeFactory.literalNode(hexadecimalIndex);
-
-        NodeMetadata.set(hexadecimalLiteralNode, { replacedLiteral: true });
-
-        return hexadecimalLiteralNode;
-    }
-
-    /**
-     * @param {string} decodeKey
-     * @returns {Literal}
-     */
-    private static getRc4KeyLiteralNode (decodeKey: string): ESTree.Literal {
-        const rc4KeyLiteralNode: ESTree.Literal = NodeFactory.literalNode(decodeKey);
-
-        NodeMetadata.set(rc4KeyLiteralNode, { replacedLiteral: true });
-
-        return rc4KeyLiteralNode;
-    }
-
     /**
      * @param {string} stringArrayCallsWrapperName
      * @param {number} index
@@ -104,12 +77,12 @@ export class StringArrayCallNode extends AbstractCustomNode {
      * @returns {TStatement[]}
      */
     protected getNodeStructure (): TStatement[] {
-        const callExpressionArgs: ESTree.Literal[] = [
-            StringArrayCallNode.getHexadecimalLiteralNode(this.index)
+        const callExpressionArgs: ESTree.Expression[] = [
+            this.getHexadecimalNode(this.index)
         ];
 
         if (this.decodeKey) {
-            callExpressionArgs.push(StringArrayCallNode.getRc4KeyLiteralNode(this.decodeKey));
+            callExpressionArgs.push(this.getRc4KeyLiteralNode(this.decodeKey));
         }
 
         const stringArrayIdentifierNode: ESTree.Identifier =

+ 3 - 4
src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperFunctionNode.ts

@@ -12,13 +12,12 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { AbstractCustomNode } from '../AbstractCustomNode';
+import { AbstractStringArrayCallNode } from './AbstractStringArrayCallNode';
 import { NodeFactory } from '../../node/NodeFactory';
 import { NodeUtils } from '../../node/NodeUtils';
-import { StringArrayCallNode } from './StringArrayCallNode';
 
 @injectable()
-export class StringArrayScopeCallsWrapperFunctionNode extends AbstractCustomNode {
+export class StringArrayScopeCallsWrapperFunctionNode extends AbstractStringArrayCallNode {
     /**
      * @type {number}
      */
@@ -102,7 +101,7 @@ export class StringArrayScopeCallsWrapperFunctionNode extends AbstractCustomNode
                             NodeFactory.binaryExpressionNode(
                                 '-',
                                 firstCallArgumentIdentifierNode,
-                                StringArrayCallNode.getHexadecimalLiteralNode(this.shiftedIndex)
+                                this.getHexadecimalNode(this.shiftedIndex)
                             ),
                             secondCallArgumentIdentifierNode
                         ]

+ 2 - 2
src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperVariableNode.ts

@@ -10,12 +10,12 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { AbstractCustomNode } from '../AbstractCustomNode';
+import { AbstractStringArrayCallNode } from './AbstractStringArrayCallNode';
 import { NodeFactory } from '../../node/NodeFactory';
 import { NodeUtils } from '../../node/NodeUtils';
 
 @injectable()
-export class StringArrayScopeCallsWrapperVariableNode extends AbstractCustomNode {
+export class StringArrayScopeCallsWrapperVariableNode extends AbstractStringArrayCallNode {
     /**
      * @type {string}
      */

+ 2 - 2
src/node-transformers/string-array-transformers/StringArrayTransformer.ts

@@ -42,12 +42,12 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
     /**
      * @type {number}
      */
-    private static readonly minShiftedIndexValue: number = 10;
+    private static readonly minShiftedIndexValue: number = -1000;
 
     /**
      * @type {number}
      */
-    private static readonly maxShiftedIndexValue: number = 100;
+    private static readonly maxShiftedIndexValue: number = 1000;
 
     /**
      * @type {IEscapeSequenceEncoder}

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است