• 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

93.21
/src/types/ComponentType.ts
1
import type { BscSymbol, GetSymbolTypeOptions, SymbolTableProvider } from '../SymbolTable';
2
import { SymbolTypeFlag } from '../SymbolTypeFlag';
1✔
3
import { SymbolTable } from '../SymbolTable';
1✔
4
import { isAnyReferenceType, isComponentType, isDynamicType, isObjectType, isPrimitiveType, isReferenceType, isTypedFunctionType } from '../astUtils/reflection';
1✔
5
import type { ExtraSymbolData, TypeCompatibilityData } from '../interfaces';
6
import type { BaseFunctionType } from './BaseFunctionType';
7
import type { BscType } from './BscType';
8
import { BscTypeKind } from './BscTypeKind';
1✔
9
import { BuiltInInterfaceAdder } from './BuiltInInterfaceAdder';
1✔
10
import { InheritableType } from './InheritableType';
1✔
11
import { isUnionTypeCompatible } from './helpers';
1✔
12
import util from '../util';
1✔
13

14
export class ComponentType extends InheritableType {
1✔
15

16
    constructor(public name: string, superComponent?: ComponentType) {
172,554✔
17
        super(name, superComponent);
172,554✔
18
        this.callFuncMemberTable = new SymbolTable(`${this.name}: CallFunc`, () => this.parentComponent?.callFuncMemberTable);
172,554✔
19
        this.callFuncAssociatedTypesTable = new SymbolTable(`${this.name}: CallFuncAssociatedTypes`);
172,554✔
20
    }
21

22
    public readonly kind = BscTypeKind.ComponentType;
172,554✔
23

24
    public get parentComponent() {
25
        return this.parentType as ComponentType;
173✔
26
    }
27

28
    public isTypeCompatible(targetType: BscType, data?: TypeCompatibilityData) {
29
        if (this.isEqual(targetType)) {
178✔
30
            return true;
170✔
31
        } else if (isDynamicType(targetType) ||
8!
32
            isObjectType(targetType) ||
33
            isUnionTypeCompatible(this, targetType, data)) {
UNCOV
34
            return true;
×
35
        } else if (isComponentType(targetType)) {
8!
36
            return this.isTypeDescendent(targetType);
8✔
37
        }
UNCOV
38
        return false;
×
39
    }
40

41
    public static instance = new ComponentType('Node');
1✔
42

43
    isEqual(targetType: BscType, data: TypeCompatibilityData = {}): boolean {
206✔
44
        if (isReferenceType(targetType) && targetType.isResolvable()) {
216✔
45
            targetType = targetType.getTarget();
149✔
46
        }
47
        if (this === targetType) {
216✔
48
            return true;
189✔
49
        }
50

51
        return isComponentType(targetType) && this.name.toLowerCase() === targetType.name.toLowerCase() &&
27✔
52
            this.isParentTypeEqual(targetType, data) &&
53
            this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime, data) &&
54
            targetType.checkCompatibilityBasedOnMembers(this, SymbolTypeFlag.runtime, data) &&
55
            this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime, data, this.callFuncMemberTable) &&
56
            targetType.checkCompatibilityBasedOnMembers(this, SymbolTypeFlag.runtime, data, this.callFuncMemberTable);
57
    }
58

59
    public toString() {
60
        return util.getSgNodeTypeName(this.name);
465✔
61
    }
62

63
    private builtInMemberTable: SymbolTable;
64

65
    getBuiltInMemberTable(): SymbolTable {
66
        if (!this.parentType) {
172,552✔
67
            if (this.builtInMemberTable) {
12,567!
UNCOV
68
                return this.builtInMemberTable;
×
69
            }
70
            this.builtInMemberTable = new SymbolTable(`${this.__identifier} Built-in Members`);
12,567✔
71
            this.pushMemberProvider(() => this.builtInMemberTable);
12,567✔
72
            return this.builtInMemberTable;
12,567✔
73
        }
74
    }
75

76
    private hasStartedAddingBuiltInInterfaces = false;
172,554✔
77

78
    addBuiltInInterfaces() {
79
        if (!this.hasAddedBuiltInInterfaces && !this.hasStartedAddingBuiltInInterfaces) {
334,299✔
80
            this.hasStartedAddingBuiltInInterfaces = true;
172,552✔
81
            if (this.parentType) {
172,552✔
82
                this.parentType.addBuiltInInterfaces();
159,985✔
83
            }
84
            BuiltInInterfaceAdder.addBuiltInInterfacesToType(this);
172,552✔
85
        }
86
        this.hasAddedBuiltInInterfaces = true;
334,299✔
87
        this.addBuiltInFields();
334,299✔
88
    }
89

90
    private hasAddedBuiltInFields = false;
172,554✔
91
    private hasStartedAddingBuiltInFields = false;
172,554✔
92

93

94
    addBuiltInFields() {
95
        if (!this.hasAddedBuiltInFields && !this.hasStartedAddingBuiltInFields) {
494,265✔
96
            this.hasStartedAddingBuiltInFields = true;
172,552✔
97
            if (isComponentType(this.parentType)) {
172,552✔
98
                this.parentType.addBuiltInFields();
159,966✔
99
            }
100
            BuiltInInterfaceAdder.addBuiltInFieldsToNodeType(this);
172,552✔
101
        }
102
        this.hasAddedBuiltInFields = true;
494,265✔
103
    }
104

105
    public readonly callFuncMemberTable: SymbolTable;
106
    public readonly callFuncAssociatedTypesTable: SymbolTable;
107

108
    /**
109
     * Adds a function to the call func member table
110
     * Also adds any associated custom types to its own table, so they can be used through a callfunc
111
     */
112
    addCallFuncMember(name: string, data: ExtraSymbolData, funcType: BaseFunctionType, flags: SymbolTypeFlag, associatedTypesTableProvider?: SymbolTableProvider) {
113
        const originalTypesToCheck = new Set<BscType>();
44✔
114
        if (isTypedFunctionType(funcType)) {
44✔
115
            const paramTypes = (funcType.params ?? []).map(p => p.type);
54!
116
            for (const paramType of paramTypes) {
40✔
117
                originalTypesToCheck.add(paramType);
54✔
118
            }
119
        }
120
        if (funcType.returnType) {
44!
121
            originalTypesToCheck.add(funcType.returnType);
44✔
122
        }
123
        const additionalTypesToCheck = new Set<BscType>();
44✔
124
        /*function addSubTypes(type: BscType) {
125
            const subSymbols = type.getMemberTable().getAllSymbols(SymbolTypeFlag.runtime);
126
            for (const subSymbol of subSymbols) {
127
                if (!subSymbol.type.isBuiltIn && !(additionalTypesToCheck.has(subSymbol.type) || originalTypesToCheck.has(subSymbol.type))) {
128
                    // if this is a custom type, and we haven't added it to the types to check to see if can add it to the additional types
129
                    // add the type, and investigate any members
130
                    additionalTypesToCheck.add(subSymbol.type);
131
                    addSubTypes(subSymbol.type);
132
                }
133

134
            }
135
        }*/
136

137
        for (const type of originalTypesToCheck) {
44✔
138
            if (!type.isBuiltIn) {
64✔
139
                util.getCustomTypesInSymbolTree(additionalTypesToCheck, type, (subSymbol: BscSymbol) => {
6✔
140
                    return !originalTypesToCheck.has(subSymbol.type);
3✔
141
                });
142

143

144
                //addSubTypes(type);
145
            }
146
        }
147

148
        for (const type of [...originalTypesToCheck.values(), ...additionalTypesToCheck.values()]) {
44✔
149
            if (!isPrimitiveType(type) && type.isResolvable()) {
67✔
150
                // This type is a reference type, but was able to be resolved here
151
                // add it to the table of associated types, so it can be used through a callfunc
152
                const extraData = {};
38✔
153
                if (associatedTypesTableProvider) {
38!
154
                    associatedTypesTableProvider().getSymbolType(type.toString(), { flags: SymbolTypeFlag.typetime, data: extraData });
38✔
155
                }
156
                let targetType = isAnyReferenceType(type) ? type.getTarget?.() : type;
38✔
157

158
                this.callFuncAssociatedTypesTable.addSymbol(type.toString(), { ...extraData, isFromCallFunc: true }, targetType, SymbolTypeFlag.typetime);
38✔
159
            }
160
        }
161

162
        // add this function to be available through callfunc
163
        this.callFuncMemberTable.addSymbol(name, data, funcType, flags);
44✔
164
    }
165

166
    getCallFuncTable() {
167
        return this.callFuncMemberTable;
3✔
168
    }
169

170
    getCallFuncType(name: string, options: GetSymbolTypeOptions) {
171
        const callFuncType = this.callFuncMemberTable.getSymbolType(name, options);
237✔
172

173
        const addAssociatedTypesTableAsSiblingToMemberTable = (type: BscType) => {
234✔
174
            if (isReferenceType(type) &&
434✔
175
                !type.isResolvable()) {
176
                // This param or return type is a reference - make sure the associated types are included
177
                type.tableProvider().addSibling(this.callFuncAssociatedTypesTable);
4✔
178

179
                // add this as a sister table to member tables too!
180
                const memberTable: SymbolTable = type.getMemberTable();
4✔
181
                if (memberTable.getAllSymbols) {
4!
182
                    for (const memberSymbol of memberTable.getAllSymbols(SymbolTypeFlag.runtime)) {
4✔
183
                        addAssociatedTypesTableAsSiblingToMemberTable(memberSymbol?.type);
6!
184
                    }
185
                }
186

187
            }
188
        };
189

190
        if (isTypedFunctionType(callFuncType)) {
234✔
191
            const typesToCheck = [...callFuncType.params.map(p => p.type), callFuncType.returnType];
228✔
192

193
            for (const type of typesToCheck) {
228✔
194
                addAssociatedTypesTableAsSiblingToMemberTable(type);
428✔
195
            }
196
        }
197

198
        return callFuncType;
234✔
199
    }
200
}
201

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