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

rokucommunity / brighterscript / #13308

22 Nov 2024 02:25PM UTC coverage: 86.801%. Remained the same
#13308

push

web-flow
Merge 332332a1f into 2a6afd921

11833 of 14419 branches covered (82.07%)

Branch coverage included in aggregate %.

191 of 205 new or added lines in 26 files covered. (93.17%)

201 existing lines in 18 files now uncovered.

12868 of 14038 relevant lines covered (91.67%)

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

20
    public get dependencyGraphKey() {
21
        return this.xmlFile.dependencyGraphKey;
900✔
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,985✔
30
            let scope: Scope | undefined;
31
            let parentComponentName = this.xmlFile.parentComponentName?.text;
458✔
32
            if (parentComponentName) {
458✔
33
                scope = this.program.getComponentScope(parentComponentName);
444✔
34
            }
35
            if (scope) {
458✔
36
                return scope;
35✔
37
            } else {
38
                return this.program.globalScope ?? null;
423!
39
            }
40
        });
41
    }
42

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

76
    public getAllFiles() {
77
        return this.cache.getOrAdd('getAllFiles-xmlScope', () => {
6,695✔
78
            const allFiles = super.getAllFiles();
487✔
79
            allFiles.push(this.xmlFile);
487✔
80
            return allFiles;
487✔
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', () => {
12,507✔
90
            let result = [
491✔
91
                this.xmlFile
92
            ] as BscFile[];
93
            let scriptDestPaths = this.xmlFile.getOwnDependencies();
491✔
94
            for (let destPath of scriptDestPaths) {
491✔
95
                let file = this.program.getFile(destPath, false);
1,426✔
96
                if (file) {
1,426✔
97
                    result.push(file);
779✔
98
                }
99
            }
100
            return result;
491✔
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