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

rokucommunity / brighterscript / #13125

01 Oct 2024 02:12PM UTC coverage: 86.842% (-1.4%) from 88.193%
#13125

push

web-flow
Merge d4a9e5fff into 3a2dc7282

11554 of 14068 branches covered (82.13%)

Branch coverage included in aggregate %.

7000 of 7592 new or added lines in 100 files covered. (92.2%)

83 existing lines in 18 files now uncovered.

12701 of 13862 relevant lines covered (91.62%)

29529.09 hits per line

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

90.82
/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

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

19
    public get dependencyGraphKey() {
20
        return this.xmlFile.dependencyGraphKey;
858✔
21
    }
22

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

42
    public getComponentType() {
43
        let componentElement = this.xmlFile.ast.componentElement;
301✔
44
        if (!componentElement?.name) {
301!
UNCOV
45
            return;
×
46
        }
47
        const parentComponentType = componentElement?.extends
301!
48
            ? this.symbolTable.getSymbolType(util.getSgNodeTypeName(componentElement?.extends), { flags: SymbolTypeFlag.typetime, fullName: componentElement?.extends, tableProvider: () => this.symbolTable })
38!
49
            : undefined;
50
        const result = new ComponentType(componentElement.name, parentComponentType as ComponentType);
301✔
51
        result.addBuiltInInterfaces();
301✔
52
        const iface = componentElement.interfaceElement;
301✔
53
        if (!iface) {
301✔
54
            return result;
270✔
55
        }
56
        //add functions
57
        for (const func of iface.functions ?? []) {
31!
58
            if (func.name) {
33✔
59
                const componentFuncType = this.symbolTable.getSymbolType(func.name, { flags: SymbolTypeFlag.runtime, fullName: func.name, tableProvider: () => this.symbolTable });
30✔
60
                // TODO: Get correct function type, and fully resolve all param and return types of function
61
                // eg.:
62
                // callFuncType = new CallFuncType(componentFuncType) // does something to fully resolve & store all associated types
63

64
                //TODO: add documentation - need to get previous comment from XML
65
                result.addCallFuncMember(func.name, {}, componentFuncType as BaseFunctionType, SymbolTypeFlag.runtime);
30✔
66
            }
67
        }
68
        //add fields
69
        for (const field of iface.fields ?? []) {
31!
70
            if (field.id) {
28✔
71
                const actualFieldType = field.type ? util.getNodeFieldType(field.type, this.symbolTable) : DynamicType.instance;
25✔
72
                //TODO: add documentation - need to get previous comment from XML
73
                result.addMember(field.id, {}, actualFieldType, SymbolTypeFlag.runtime);
25✔
74
            }
75
        }
76
        return result;
31✔
77
    }
78

79
    public getAllFiles() {
80
        return this.cache.getOrAdd('getAllFiles-xmlScope', () => {
5,464✔
81
            const allFiles = super.getAllFiles();
466✔
82
            allFiles.push(this.xmlFile);
466✔
83
            return allFiles;
466✔
84
        });
85
    }
86

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