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

rokucommunity / brighterscript / #13319

25 Nov 2024 02:52PM UTC coverage: 86.872%. Remained the same
#13319

push

web-flow
Merge d9b225566 into 2a6afd921

11934 of 14527 branches covered (82.15%)

Branch coverage included in aggregate %.

300 of 316 new or added lines in 31 files covered. (94.94%)

240 existing lines in 20 files now uncovered.

12960 of 14129 relevant lines covered (91.73%)

32480.01 hits per line

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

90.91
/src/XmlScope.ts
1
import { Scope } from './Scope';
1✔
2
import type { XmlFile } from './files/XmlFile';
3
import type { Program } from './Program';
4
import util from './util';
1✔
5
import { SymbolTypeFlag } from './SymbolTypeFlag';
1✔
6
import type { BscFile } from './files/BscFile';
7
import { DynamicType } from './types/DynamicType';
1✔
8
import type { BaseFunctionType } from './types/BaseFunctionType';
9
import { ComponentType } from './types/ComponentType';
1✔
10
import type { ExtraSymbolData } from './interfaces';
11

12
export class XmlScope extends Scope {
1✔
13
    constructor(
14
        public xmlFile: XmlFile,
404✔
15
        public program: Program
404✔
16
    ) {
17
        super(xmlFile.destPath, program);
404✔
18
    }
19

20
    public get dependencyGraphKey() {
21
        return this.xmlFile.dependencyGraphKey;
1,314✔
22
    }
23

24
    /**
25
     * Get the parent scope of this scope. If we could find the scope for our parentComponent, use that.
26
     * Otherwise default to global scope
27
     */
28
    public getParentScope() {
29
        return this.cache.getOrAdd('parentScope', () => {
1,977✔
30
            let scope: Scope | undefined;
31
            let parentComponentName = this.xmlFile.parentComponentName?.text;
738✔
32
            if (parentComponentName) {
738✔
33
                scope = this.program.getComponentScope(parentComponentName);
724✔
34
            }
35
            if (scope) {
738✔
36
                return scope;
65✔
37
            } else {
38
                return this.program.globalScope ?? null;
673!
39
            }
40
        });
41
    }
42

43
    public getComponentType() {
44
        let componentElement = this.xmlFile.ast.componentElement;
328✔
45
        if (!componentElement?.name) {
328!
UNCOV
46
            return;
×
47
        }
48
        const parentComponentType = componentElement?.extends
328!
49
            ? this.symbolTable.getSymbolType(util.getSgNodeTypeName(componentElement?.extends), { flags: SymbolTypeFlag.typetime, fullName: componentElement?.extends, tableProvider: () => this.symbolTable })
38!
50
            : undefined;
51
        const result = new ComponentType(componentElement.name, parentComponentType as ComponentType);
328✔
52
        result.addBuiltInInterfaces();
328✔
53
        const iface = componentElement.interfaceElement;
328✔
54
        if (!iface) {
328✔
55
            return result;
276✔
56
        }
57
        //add functions
58
        for (const func of iface.functions ?? []) {
52!
59
            if (func.name) {
47✔
60
                const extraData: ExtraSymbolData = {};
44✔
61
                const componentFuncType = this.symbolTable.getSymbolType(func.name, { flags: SymbolTypeFlag.runtime, data: extraData, fullName: func.name, tableProvider: () => this.symbolTable });
44✔
62
                result.addCallFuncMember(func.name, extraData, componentFuncType as BaseFunctionType, SymbolTypeFlag.runtime, () => this.symbolTable);
44✔
63
            }
64
        }
65
        //add fields
66
        for (const field of iface.fields ?? []) {
52!
67
            if (field.id) {
35✔
68
                const actualFieldType = field.type ? util.getNodeFieldType(field.type, this.symbolTable) : DynamicType.instance;
32✔
69
                //TODO: add documentation - need to get previous comment from XML
70
                result.addMember(field.id, {}, actualFieldType, SymbolTypeFlag.runtime);
32✔
71
            }
72
        }
73
        return result;
52✔
74
    }
75

76
    public getAllFiles() {
77
        return this.cache.getOrAdd('getAllFiles-xmlScope', () => {
7,052✔
78
            const allFiles = super.getAllFiles();
895✔
79
            allFiles.push(this.xmlFile);
895✔
80
            return allFiles;
895✔
81
        });
82
    }
83

84
    /**
85
     * Get the list of files referenced by this scope that are actually loaded in the program.
86
     * This does not account for parent scope.
87
     */
88
    public getOwnFiles() {
89
        return this.cache.getOrAdd('getOwnFiles', () => {
33,480✔
90
            let result = [
1,214✔
91
                this.xmlFile
92
            ] as BscFile[];
93
            let scriptDestPaths = this.xmlFile.getOwnDependencies();
1,214✔
94
            for (let destPath of scriptDestPaths) {
1,214✔
95
                let file = this.program.getFile(destPath, false);
3,887✔
96
                if (file) {
3,887✔
97
                    result.push(file);
2,185✔
98
                }
99
            }
100
            return result;
1,214✔
101
        });
102
    }
103
}
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