• 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

82.14
/src/custom-code-helpers/AbstractCustomCodeHelper.ts
1
import { inject, injectable } from 'inversify';
6✔
2
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
6✔
3

4
import { TIdentifierNamesGeneratorFactory } from '../types/container/generators/TIdentifierNamesGeneratorFactory';
5
import { TStatement } from '../types/node/TStatement';
6

7
import { ICustomCodeHelper } from '../interfaces/custom-code-helpers/ICustomCodeHelper';
8
import { ICustomCodeHelperFormatter } from '../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
9
import { ICustomCodeHelperObfuscator } from '../interfaces/custom-code-helpers/ICustomCodeHelperObfuscator';
10
import { IIdentifierNamesGenerator } from '../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
11
import { IOptions } from '../interfaces/options/IOptions';
12
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
13

14
import { GlobalVariableTemplate1 } from './common/templates/GlobalVariableTemplate1';
6✔
15
import { GlobalVariableTemplate2 } from './common/templates/GlobalVariableTemplate2';
6✔
16
import { ObfuscationTarget } from '../enums/ObfuscationTarget';
6✔
17
import { GlobalVariableNoEvalTemplate } from './common/templates/GlobalVariableNoEvalTemplate';
6✔
18
import { GlobalVariableServiceWorkerTemplate } from './common/templates/GlobalVariableServiceWorkerTemplate';
6✔
19

20
@injectable()
21
export abstract class AbstractCustomCodeHelper<TInitialData extends unknown[] = unknown[]>
6✔
22
    implements ICustomCodeHelper<TInitialData>
23
{
24
    /**
25
     * @type {string[]}
26
     */
27
    private static readonly globalVariableTemplateFunctions: string[] = [
6✔
28
        GlobalVariableTemplate1(),
29
        GlobalVariableTemplate2()
30
    ];
31

32
    /**
33
     * @type {TStatement[] | null}
34
     */
35
    protected cachedNode: TStatement[] | null = null;
200,394✔
36

37
    /**
38
     * @type {ICustomCodeHelperFormatter}
39
     */
40
    protected readonly customCodeHelperFormatter: ICustomCodeHelperFormatter;
41

42
    /**
43
     * @type {ICustomCodeHelperObfuscator}
44
     */
45
    protected readonly customCodeHelperObfuscator: ICustomCodeHelperObfuscator;
46

47
    /**
48
     * @type {IIdentifierNamesGenerator}
49
     */
50
    protected readonly identifierNamesGenerator: IIdentifierNamesGenerator;
51

52
    /**
53
     * @type {IOptions}
54
     */
55
    protected readonly options: IOptions;
56

57
    /**
58
     * @type {IRandomGenerator}
59
     */
60
    protected readonly randomGenerator: IRandomGenerator;
61

62
    /**
63
     * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
64
     * @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
65
     * @param {ICustomCodeHelperObfuscator} customCodeHelperObfuscator
66
     * @param {IRandomGenerator} randomGenerator
67
     * @param {IOptions} options
68
     */
69
    public constructor(
70
        @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
71
        identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
72
        @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter,
73
        @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator,
74
        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
75
        @inject(ServiceIdentifiers.IOptions) options: IOptions
76
    ) {
77
        this.identifierNamesGenerator = identifierNamesGeneratorFactory(options);
200,394✔
78
        this.customCodeHelperFormatter = customCodeHelperFormatter;
200,394✔
79
        this.customCodeHelperObfuscator = customCodeHelperObfuscator;
200,394✔
80
        this.randomGenerator = randomGenerator;
200,394✔
81
        this.options = options;
200,394✔
82
    }
83

84
    /**
85
     * @returns {TStatement[]}
86
     */
87
    public getNode(): TStatement[] {
88
        if (!this.cachedNode) {
199,476✔
89
            const codeHelperTemplate: string = this.getCodeHelperTemplate();
199,476✔
90

91
            this.cachedNode = this.customCodeHelperFormatter.formatStructure(this.getNodeStructure(codeHelperTemplate));
199,476✔
92
        }
93

94
        return this.cachedNode;
199,476✔
95
    }
96

97
    /**
98
     * @returns {string}
99
     */
100
    protected getGlobalVariableTemplate(): string {
101
        switch (this.options.target) {
1,596✔
102
            case ObfuscationTarget.BrowserNoEval:
1,596!
103
                return GlobalVariableNoEvalTemplate();
×
104
            case ObfuscationTarget.ServiceWorker:
105
                return GlobalVariableServiceWorkerTemplate();
×
106
            default:
107
                return this.randomGenerator
1,596✔
108
                    .getRandomGenerator()
109
                    .pickone(AbstractCustomCodeHelper.globalVariableTemplateFunctions);
110
        }
111
    }
112

113
    /**
114
     * @returns {string}
115
     */
116
    protected getCodeHelperTemplate(): string {
117
        return '';
×
118
    }
119

120
    /**
121
     * @param {TInitialData} args
122
     */
123
    public abstract initialize(...args: TInitialData): void;
124

125
    /**
126
     * @returns {TStatement[]}
127
     */
128
    protected abstract getNodeStructure(codeHelperTemplate: string): TStatement[];
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