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

rokucommunity / brighterscript / #13978

10 Mar 2025 01:00PM UTC coverage: 86.759% (-2.4%) from 89.113%
#13978

push

web-flow
Merge 96004e807 into 700183e7d

12688 of 15459 branches covered (82.08%)

Branch coverage included in aggregate %.

28 of 28 new or added lines in 1 file covered. (100.0%)

924 existing lines in 53 files now uncovered.

13614 of 14857 relevant lines covered (91.63%)

19945.24 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,
423✔
15
        public program: Program
423✔
16
    ) {
17
        super(xmlFile.destPath, program);
423✔
18
    }
19

20
    public get dependencyGraphKey() {
21
        return this.xmlFile.dependencyGraphKey;
1,373✔
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', () => {
2,234✔
30
            let scope: Scope | undefined;
31
            let parentComponentName = this.xmlFile.parentComponentName?.text;
905✔
32
            if (parentComponentName) {
905✔
33
                scope = this.program.getComponentScope(parentComponentName);
891✔
34
            }
35
            if (scope) {
905✔
36
                return scope;
65✔
37
            } else {
38
                return this.program.globalScope ?? null;
840!
39
            }
40
        });
41
    }
42

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

76
    public getAllFiles() {
77
        return this.cache.getOrAdd('getAllFiles-xmlScope', () => {
7,930✔
78
            const allFiles = super.getAllFiles();
932✔
79
            allFiles.push(this.xmlFile);
932✔
80
            return allFiles;
932✔
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', () => {
44,475✔
90
            let result = [
1,251✔
91
                this.xmlFile
92
            ] as BscFile[];
93
            let scriptDestPaths = this.xmlFile.getOwnDependencies();
1,251✔
94
            for (let destPath of scriptDestPaths) {
1,251✔
95
                let file = this.program.getFile(destPath, false);
3,912✔
96
                if (file) {
3,912✔
97
                    result.push(file);
2,214✔
98
                }
99
            }
100
            return result;
1,251✔
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