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

javascript-obfuscator / javascript-obfuscator / 13621494893

15 Jun 2024 05:29PM CUT coverage: 97.297%. Remained the same
13621494893

push

github

web-flow
Update CHANGELOG.md

2238 of 2373 branches covered (94.31%)

Branch coverage included in aggregate %.

5645 of 5729 relevant lines covered (98.53%)

33055580.69 hits per line

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

88.0
/src/code-transformers/preparing-transformers/HashbangOperatorTransformer.ts
1
import { inject, injectable, } from 'inversify';
6✔
2
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
6✔
3

4
import { IOptions } from '../../interfaces/options/IOptions';
5
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
6

7
import { CodeTransformationStage } from '../../enums/code-transformers/CodeTransformationStage';
6✔
8

9
import { AbstractCodeTransformer } from '../AbstractCodeTransformer';
6✔
10

11
@injectable()
12
export class HashbangOperatorTransformer extends AbstractCodeTransformer {
6✔
13
    /**
14
     * @type {string | null}
15
     */
16
    private hashbangOperatorLine: string | null = null;
197,686✔
17

18
    /**
19
     * @param {IRandomGenerator} randomGenerator
20
     * @param {IOptions} options
21
     */
22
    public constructor (
23
        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
24
        @inject(ServiceIdentifiers.IOptions) options: IOptions
25
    ) {
26
        super(randomGenerator, options);
197,686✔
27
    }
28

29
    /**
30
     * Removes hashbang operator before AST transformation and appends it back after
31
     *
32
     * @param {string} code
33
     * @param {CodeTransformationStage} codeTransformationStage
34
     * @returns {string}
35
     */
36
    public transformCode (code: string, codeTransformationStage: CodeTransformationStage): string {
37
        switch (codeTransformationStage) {
395,366✔
38
            case CodeTransformationStage.PreparingTransformers:
395,366!
39
                return this.removeAndSaveHashbangOperatorLine(code);
197,686✔
40

41
            case CodeTransformationStage.FinalizingTransformers:
42
                return this.appendSavedHashbangOperatorLine(code);
197,680✔
43

44
            default:
45
                return code;
×
46
        }
47
    }
48

49
    /**
50
     * @param {string} code
51
     * @returns {string}
52
     */
53
    private removeAndSaveHashbangOperatorLine (code: string): string {
54
        return code
197,686✔
55
            .replace(/^#!.*$(\r?\n)*/m, (substring: string) => {
56
                if (substring) {
18!
57
                    this.hashbangOperatorLine = substring;
18✔
58
                }
59

60
                return '';
18✔
61
            })
62
            .trim();
63
    }
64

65
    /**
66
     * @param {string} code
67
     * @returns {string}
68
     */
69
    private appendSavedHashbangOperatorLine (code: string): string {
70
        return `${this.hashbangOperatorLine ?? ''}${code}`;
197,680✔
71
    }
72
}
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

© 2025 Coveralls, Inc