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

rokucommunity / brighterscript / #13388

29 Nov 2024 07:55PM UTC coverage: 86.824%. Remained the same
#13388

push

web-flow
Merge b1d7d7253 into 57fa2ad4d

12087 of 14723 branches covered (82.1%)

Branch coverage included in aggregate %.

379 of 407 new or added lines in 36 files covered. (93.12%)

244 existing lines in 22 files now uncovered.

13071 of 14253 relevant lines covered (91.71%)

33084.46 hits per line

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

87.94
/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) {
175,090✔
17
        super(name, superComponent);
175,090✔
18
        this.callFuncMemberTable = new SymbolTable(`${this.name}: CallFunc`, () => this.parentComponent?.callFuncMemberTable);
175,090✔
19
        this.callFuncAssociatedTypesTable = new SymbolTable(`${this.name}: CallFuncAssociatedTypes`, () => this.parentComponent?.callFuncAssociatedTypesTable);
175,090!
20
    }
21

22
    public readonly kind = BscTypeKind.ComponentType;
175,090✔
23

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

28
    public isTypeCompatible(targetType: BscType, data?: TypeCompatibilityData) {
29
        if (this.isEqual(targetType)) {
2,428✔
30
            return true;
2,420✔
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 {
2,446✔
44
        if (isReferenceType(targetType) && targetType.isResolvable()) {
3,047✔
45
            targetType = targetType.getTarget?.() ?? targetType;
2,742!
46
        }
47
        if (this === targetType) {
3,047✔
48
            return true;
2,890✔
49
        }
50
        if (!isComponentType(targetType)) {
157!
NEW
51
            return false;
×
52
        }
53

54
        const thisNameLower = this.name.toLowerCase();
157✔
55
        const targetNameLower = targetType.name.toLowerCase();
157✔
56
        if (thisNameLower !== targetNameLower) {
157✔
57
            return false;
18✔
58
        }
59
        if (this.isBuiltIn && targetType.isBuiltIn) {
139!
NEW
60
            return true;
×
61
        }
62

63
        if (!this.isParentTypeEqual(targetType, data)) {
139!
NEW
64
            return false;
×
65
        }
66
        if (!this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime, data) ||
139✔
67
            !targetType.checkCompatibilityBasedOnMembers(this, SymbolTypeFlag.runtime, data)) {
68
            return false;
4✔
69
        }
70
        if (!this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime, data, this.callFuncMemberTable, targetType.callFuncMemberTable) ||
135✔
71
            !targetType.checkCompatibilityBasedOnMembers(this, SymbolTypeFlag.runtime, data, targetType.callFuncMemberTable, this.callFuncMemberTable)) {
72
            return false;
3✔
73
        }
74

75
        return true;
132✔
76
    }
77

78
    public toString() {
79
        return util.getSgNodeTypeName(this.name);
499✔
80
    }
81

82
    private builtInMemberTable: SymbolTable;
83

84
    getBuiltInMemberTable(): SymbolTable {
85
        if (!this.parentType) {
175,088✔
86
            if (this.builtInMemberTable) {
12,741!
UNCOV
87
                return this.builtInMemberTable;
×
88
            }
89
            this.builtInMemberTable = new SymbolTable(`${this.__identifier} Built-in Members`);
12,741✔
90
            this.pushMemberProvider(() => this.builtInMemberTable);
22,096✔
91
            return this.builtInMemberTable;
12,741✔
92
        }
93
    }
94

95
    private hasStartedAddingBuiltInInterfaces = false;
175,090✔
96

97
    addBuiltInInterfaces() {
98
        if (!this.hasAddedBuiltInInterfaces && !this.hasStartedAddingBuiltInInterfaces) {
339,188✔
99
            this.hasStartedAddingBuiltInInterfaces = true;
175,088✔
100
            if (this.parentType) {
175,088✔
101
                this.parentType.addBuiltInInterfaces();
162,347✔
102
            }
103
            BuiltInInterfaceAdder.addBuiltInInterfacesToType(this);
175,088✔
104
        }
105
        this.hasAddedBuiltInInterfaces = true;
339,188✔
106
        this.addBuiltInFields();
339,188✔
107
    }
108

109
    private hasAddedBuiltInFields = false;
175,090✔
110
    private hasStartedAddingBuiltInFields = false;
175,090✔
111

112

113
    addBuiltInFields() {
114
        if (!this.hasAddedBuiltInFields && !this.hasStartedAddingBuiltInFields) {
501,512✔
115
            this.hasStartedAddingBuiltInFields = true;
175,088✔
116
            if (isComponentType(this.parentType)) {
175,088✔
117
                this.parentType.addBuiltInFields();
162,324✔
118
            }
119
            BuiltInInterfaceAdder.addBuiltInFieldsToNodeType(this);
175,088✔
120
        }
121
        this.hasAddedBuiltInFields = true;
501,512✔
122
    }
123

124
    public readonly callFuncMemberTable: SymbolTable;
125
    public readonly callFuncAssociatedTypesTable: SymbolTable;
126

127
    /**
128
     * Adds a function to the call func member table
129
     * Also adds any associated custom types to its own table, so they can be used through a callfunc
130
     */
131
    addCallFuncMember(name: string, data: ExtraSymbolData, funcType: BaseFunctionType, flags: SymbolTypeFlag, associatedTypesTableProvider?: SymbolTableProvider) {
132
        const originalTypesToCheck = new Set<BscType>();
51✔
133
        if (isTypedFunctionType(funcType)) {
51✔
134
            const paramTypes = (funcType.params ?? []).map(p => p.type);
58!
135
            for (const paramType of paramTypes) {
47✔
136
                originalTypesToCheck.add(paramType);
58✔
137
            }
138
        }
139
        if (funcType.returnType) {
51!
140
            originalTypesToCheck.add(funcType.returnType);
51✔
141
        }
142
        const additionalTypesToCheck = new Set<BscType>();
51✔
143

144
        for (const type of originalTypesToCheck) {
51✔
145
            if (!type.isBuiltIn) {
75✔
146
                util.getCustomTypesInSymbolTree(additionalTypesToCheck, type, (subSymbol: BscSymbol) => {
6✔
147
                    return !originalTypesToCheck.has(subSymbol.type);
3✔
148
                });
149
            }
150
        }
151

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

162
                this.callFuncAssociatedTypesTable.addSymbol(type.toString(), { ...extraData, isFromCallFunc: true }, targetType, SymbolTypeFlag.typetime);
46✔
163
            }
164
        }
165

166
        // add this function to be available through callfunc
167
        this.callFuncMemberTable.addSymbol(name, data, funcType, flags);
51✔
168
    }
169

170
    getCallFuncTable() {
171
        return this.callFuncMemberTable;
3✔
172
    }
173

174
    getCallFuncType(name: string, options: GetSymbolTypeOptions) {
175
        const callFuncType = this.callFuncMemberTable.getSymbolType(name, options);
239✔
176

177
        const addAssociatedTypesTableAsSiblingToMemberTable = (type: BscType) => {
236✔
178
            if (isReferenceType(type) &&
438✔
179
                !type.isResolvable()) {
180
                // This param or return type is a reference - make sure the associated types are included
181
                type.tableProvider().addSibling(this.callFuncAssociatedTypesTable);
4✔
182

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

193
        if (isTypedFunctionType(callFuncType)) {
236✔
194
            const typesToCheck = [...callFuncType.params.map(p => p.type), callFuncType.returnType];
230✔
195

196
            for (const type of typesToCheck) {
230✔
197
                addAssociatedTypesTableAsSiblingToMemberTable(type);
432✔
198
            }
199
        }
200

201
        return callFuncType;
236✔
202
    }
203
}
204

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