• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

javascript-obfuscator / javascript-obfuscator / 19907815758

03 Dec 2025 08:27PM UTC coverage: 97.319%. Remained the same
19907815758

push

github

sanex3339
Adjust precommit hook

1770 of 1891 branches covered (93.6%)

Branch coverage included in aggregate %.

5671 of 5755 relevant lines covered (98.54%)

34102965.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts
1
import { inject, injectable } from 'inversify';
6✔
2
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
6✔
3

4
import * as ESTree from 'estree';
5

6
import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
7
import { TStringArrayIndexesType } from '../../types/options/TStringArrayIndexesType';
8
import { TStringArrayIndexNodeFactory } from '../../types/container/custom-nodes/string-array-index-nodes/TStringArrayIndexNodeFactory';
9

10
import { ICustomCodeHelperFormatter } from '../../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
11
import { IOptions } from '../../interfaces/options/IOptions';
12
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
13
import { IStringArrayStorage } from '../../interfaces/storages/string-array-transformers/IStringArrayStorage';
14

15
import { StringArrayIndexesType } from '../../enums/node-transformers/string-array-transformers/StringArrayIndexesType';
6✔
16
import { StringArrayIndexNode } from '../../enums/custom-nodes/string-array-index-nodes/StringArrayIndexNode';
6✔
17

18
import { AbstractCustomNode } from '../AbstractCustomNode';
6✔
19
import { NodeFactory } from '../../node/NodeFactory';
6✔
20
import { NodeMetadata } from '../../node/NodeMetadata';
6✔
21
import { NodeUtils } from '../../node/NodeUtils';
6✔
22
import { IArrayUtils } from '../../interfaces/utils/IArrayUtils';
23

24
@injectable()
25
export abstract class AbstractStringArrayCallNode extends AbstractCustomNode {
6✔
26
    /**
27
     * Max count of root string array calls wrapper parameters
28
     *
29
     * @type {number}
30
     */
31
    protected static readonly stringArrayRootCallsWrapperParametersCount: number = 2;
6✔
32

33
    /**
34
     * @type {Map<TStringArrayIndexesType, StringArrayIndexNode>}
35
     */
36
    private static readonly stringArrayIndexNodesMap: Map<TStringArrayIndexesType, StringArrayIndexNode> = new Map([
6✔
37
        [StringArrayIndexesType.HexadecimalNumber, StringArrayIndexNode.StringArrayHexadecimalNumberIndexNode],
38
        [
39
            StringArrayIndexesType.HexadecimalNumericString,
40
            StringArrayIndexNode.StringArrayHexadecimalNumericStringIndexNode
41
        ]
42
    ]);
43

44
    /**
45
     * @type {IArrayUtils}
46
     */
47
    protected readonly arrayUtils: IArrayUtils;
48

49
    /**
50
     * @type {IStringArrayStorage}
51
     */
52
    protected readonly stringArrayStorage: IStringArrayStorage;
53

54
    /**
55
     * @type {TStringArrayIndexNodeFactory}
56
     */
57
    private readonly stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory;
58

59
    /**
60
     * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
61
     * @param {TStringArrayIndexNodeFactory} stringArrayIndexNodeFactory
62
     * @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
63
     * @param {IStringArrayStorage} stringArrayStorage
64
     * @param {IArrayUtils} arrayUtils
65
     * @param {IRandomGenerator} randomGenerator
66
     * @param {IOptions} options
67
     */
68
    public constructor(
69
        @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
70
        identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
71
        @inject(ServiceIdentifiers.Factory__IStringArrayIndexNode)
72
        stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory,
73
        @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter,
74
        @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage,
75
        @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils,
76
        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
77
        @inject(ServiceIdentifiers.IOptions) options: IOptions
78
    ) {
79
        super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options);
10,252,399✔
80

81
        this.stringArrayIndexNodeFactory = stringArrayIndexNodeFactory;
10,252,399✔
82
        this.stringArrayStorage = stringArrayStorage;
10,252,399✔
83
        this.arrayUtils = arrayUtils;
10,252,399✔
84
    }
85

86
    /**
87
     * @param {number} index
88
     * @returns {Expression}
89
     */
90
    protected getStringArrayIndexNode(index: number): ESTree.Expression {
91
        const isPositive: boolean = index >= 0;
63,568,532✔
92
        const normalizedIndex: number = Math.abs(index);
63,568,532✔
93

94
        const stringArrayCallsIndexType: TStringArrayIndexesType = this.randomGenerator
63,568,532✔
95
            .getRandomGenerator()
96
            .pickone(this.options.stringArrayIndexesType);
97
        const stringArrayIndexNodeName: StringArrayIndexNode | null =
98
            AbstractStringArrayCallNode.stringArrayIndexNodesMap.get(stringArrayCallsIndexType) ?? null;
63,568,532!
99

100
        if (!stringArrayIndexNodeName) {
63,568,532!
101
            throw new Error('Invalid string array index node name');
×
102
        }
103

104
        const stringArrayCallIndexNode: ESTree.Expression =
105
            this.stringArrayIndexNodeFactory(stringArrayIndexNodeName).getNode(normalizedIndex);
63,568,532✔
106

107
        NodeMetadata.set(stringArrayCallIndexNode, { stringArrayCallLiteralNode: true });
63,568,532✔
108

109
        const hexadecimalNode: ESTree.Expression = isPositive
63,568,532✔
110
            ? stringArrayCallIndexNode
63,568,532✔
111
            : NodeFactory.unaryExpressionNode('-', stringArrayCallIndexNode);
112

113
        NodeUtils.parentizeAst(hexadecimalNode);
63,568,532✔
114

115
        return hexadecimalNode;
63,568,532✔
116
    }
117

118
    /**
119
     * @param {string} decodeKey
120
     * @returns {Literal}
121
     */
122
    protected getRc4KeyLiteralNode(decodeKey: string): ESTree.Literal {
123
        const rc4KeyLiteralNode: ESTree.Literal = NodeFactory.literalNode(decodeKey);
2,641,693✔
124

125
        NodeMetadata.set(rc4KeyLiteralNode, { stringArrayCallLiteralNode: true });
2,641,693✔
126

127
        return rc4KeyLiteralNode;
2,641,693✔
128
    }
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc