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

rokucommunity / brighterscript / #13768

16 Jan 2024 07:10PM UTC coverage: 88.101% (+0.05%) from 88.056%
#13768

push

TwitchBronBron
0.65.17

5759 of 7011 branches covered (82.14%)

Branch coverage included in aggregate %.

8612 of 9301 relevant lines covered (92.59%)

1666.09 hits per line

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

80.77
/src/PluginInterface.ts
1
import type { CompilerPlugin } from './interfaces';
2
import type { Logger } from './Logger';
3
import { LogLevel } from './Logger';
1✔
4

5
// inspiration: https://github.com/andywer/typed-emitter/blob/master/index.d.ts
6
export type Arguments<T> = [T] extends [(...args: infer U) => any]
7
    ? U
8
    : [T] extends [void] ? [] : [T];
9

10
export default class PluginInterface<T extends CompilerPlugin = CompilerPlugin> {
1✔
11

12
    /**
13
     * @deprecated use the `options` parameter pattern instead
14
     */
15
    constructor(
16
        plugins: CompilerPlugin[],
17
        logger: Logger
18
    );
19
    constructor(
20
        plugins: CompilerPlugin[],
21
        options: {
22
            logger: Logger;
23
            suppressErrors?: boolean;
24
        }
25
    );
26
    constructor(
27
        private plugins: CompilerPlugin[],
1,079✔
28
        options: {
29
            logger: Logger;
30
            suppressErrors?: boolean;
31
        } | Logger
32
    ) {
33
        if (options?.constructor.name === 'Logger') {
1,079!
34
            this.logger = options as unknown as Logger;
×
35
        } else {
36
            this.logger = (options as any)?.logger;
1,079!
37
            this.suppressErrors = (options as any)?.suppressErrors === false ? false : true;
1,079!
38
        }
39
    }
40

41
    private logger: Logger;
42

43
    /**
44
     * Should plugin errors cause the program to fail, or should they be caught and simply logged
45
     */
46
    private suppressErrors: boolean | undefined;
47

48
    /**
49
     * Call `event` on plugins
50
     */
51
    public emit<K extends keyof T & string>(event: K, ...args: Arguments<T[K]>) {
52
        for (let plugin of this.plugins) {
14,260✔
53
            if ((plugin as any)[event]) {
14,871✔
54
                try {
3,662✔
55
                    this.logger.time(LogLevel.debug, [plugin.name, event], () => {
3,662✔
56
                        (plugin as any)[event](...args);
3,662✔
57
                    });
58
                } catch (err) {
59
                    this.logger.error(`Error when calling plugin ${plugin.name}.${event}:`, err);
2✔
60
                    if (!this.suppressErrors) {
2!
61
                        throw err;
×
62
                    }
63
                }
64
            }
65
        }
66
    }
67

68
    /**
69
     * Add a plugin to the beginning of the list of plugins
70
     */
71
    public addFirst<T extends CompilerPlugin = CompilerPlugin>(plugin: T) {
72
        if (!this.has(plugin)) {
1,058!
73
            this.plugins.unshift(plugin);
1,058✔
74
        }
75
        return plugin;
1,058✔
76
    }
77

78
    /**
79
     * Add a plugin to the end of the list of plugins
80
     */
81
    public add<T extends CompilerPlugin = CompilerPlugin>(plugin: T) {
82
        if (!this.has(plugin)) {
63✔
83
            this.plugins.push(plugin);
62✔
84
        }
85
        return plugin;
63✔
86
    }
87

88
    public has(plugin: CompilerPlugin) {
89
        return this.plugins.includes(plugin);
1,126✔
90
    }
91

92
    public remove<T extends CompilerPlugin = CompilerPlugin>(plugin: T) {
93
        if (this.has(plugin)) {
2!
94
            this.plugins.splice(this.plugins.indexOf(plugin));
2✔
95
        }
96
        return plugin;
2✔
97
    }
98

99
    /**
100
     * Remove all plugins
101
     */
102
    public clear() {
103
        this.plugins = [];
×
104
    }
105
}
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