• 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

92.57
/src/types/ComponentType.ts
1
import type { 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,164✔
17
        super(name, superComponent);
172,164✔
18
        this.callFuncMemberTable = new SymbolTable(`${this.name}: CallFunc`, () => this.parentComponent?.callFuncMemberTable);
172,164✔
19
        this.callFuncAssociatedTypesTable = new SymbolTable(`${this.name}: CallFuncAssociatedTypes`);
172,164✔
20
    }
21

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

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

28
    public isTypeCompatible(targetType: BscType, data?: TypeCompatibilityData) {
29
        if (this.isEqual(targetType)) {
34✔
30
            return true;
26✔
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): boolean {
44
        return isComponentType(targetType) && this.name.toLowerCase() === targetType.name.toLowerCase();
55✔
45
    }
46

47
    public toString() {
48
        return util.getSgNodeTypeName(this.name);
446✔
49
    }
50

51
    private builtInMemberTable: SymbolTable;
52

53
    getBuiltInMemberTable(): SymbolTable {
54
        if (!this.parentType) {
172,162✔
55
            if (this.builtInMemberTable) {
12,539!
UNCOV
56
                return this.builtInMemberTable;
×
57
            }
58
            this.builtInMemberTable = new SymbolTable(`${this.__identifier} Built-in Members`);
12,539✔
59
            this.pushMemberProvider(() => this.builtInMemberTable);
12,539✔
60
            return this.builtInMemberTable;
12,539✔
61
        }
62
    }
63

64

65
    addBuiltInInterfaces() {
66
        if (!this.hasAddedBuiltInInterfaces) {
331,897✔
67
            if (this.parentType) {
172,162✔
68
                this.parentType.addBuiltInInterfaces();
159,623✔
69
            }
70
            BuiltInInterfaceAdder.addBuiltInInterfacesToType(this);
172,162✔
71
        }
72
        this.hasAddedBuiltInInterfaces = true;
331,897✔
73
        this.addBuiltInFields();
331,897✔
74
    }
75

76
    private hasAddedBuiltInFields = false;
172,164✔
77

78
    addBuiltInFields() {
79
        if (!this.hasAddedBuiltInFields) {
491,501✔
80
            if (isComponentType(this.parentType)) {
172,162✔
81
                this.parentType.addBuiltInFields();
159,604✔
82
            }
83
            BuiltInInterfaceAdder.addBuiltInFieldsToNodeType(this);
172,162✔
84
        }
85
        this.hasAddedBuiltInFields = true;
491,501✔
86
    }
87

88
    public readonly callFuncMemberTable: SymbolTable;
89
    public readonly callFuncAssociatedTypesTable: SymbolTable;
90

91
    /**
92
     * Adds a function to the call func member table
93
     * Also adds any associated custom types to its own table, so they can be used through a callfunc
94
     */
95
    addCallFuncMember(name: string, data: ExtraSymbolData, funcType: BaseFunctionType, flags: SymbolTypeFlag, associatedTypesTableProvider?: SymbolTableProvider) {
96
        const originalTypesToCheck = new Set<BscType>();
45✔
97
        if (isTypedFunctionType(funcType)) {
45✔
98
            const paramTypes = (funcType.params ?? []).map(p => p.type);
54!
99
            for (const paramType of paramTypes) {
41✔
100
                originalTypesToCheck.add(paramType);
54✔
101
            }
102
        }
103
        if (funcType.returnType) {
45!
104
            originalTypesToCheck.add(funcType.returnType);
45✔
105
        }
106
        const additionalTypesToCheck = new Set<BscType>();
45✔
107
        function addSubTypes(type: BscType) {
108
            const subSymbols = type.getMemberTable().getAllSymbols(SymbolTypeFlag.runtime);
9✔
109
            for (const subSymbol of subSymbols) {
9✔
110
                if (!subSymbol.type.isBuiltIn && !(additionalTypesToCheck.has(subSymbol.type) || originalTypesToCheck.has(subSymbol.type))) {
12✔
111
                    // 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
112
                    // add the type, and investigate any members
113
                    additionalTypesToCheck.add(subSymbol.type);
3✔
114
                    addSubTypes(subSymbol.type);
3✔
115
                }
116

117
            }
118
        }
119

120
        for (const type of originalTypesToCheck) {
45✔
121
            if (!type.isBuiltIn) {
65✔
122
                addSubTypes(type);
6✔
123
            }
124
        }
125

126
        for (const type of [...originalTypesToCheck.values(), ...additionalTypesToCheck.values()]) {
45✔
127
            if (!isPrimitiveType(type) && type.isResolvable()) {
68✔
128
                // This type is a reference type, but was able to be resolved here
129
                // add it to the table of associated types, so it can be used through a callfunc
130
                const extraData = {};
38✔
131
                if (associatedTypesTableProvider) {
38!
132
                    associatedTypesTableProvider().getSymbolType(type.toString(), { flags: SymbolTypeFlag.typetime, data: extraData });
38✔
133
                }
134
                let targetType = isAnyReferenceType(type) ? type.getTarget?.() : type;
38✔
135

136
                this.callFuncAssociatedTypesTable.addSymbol(type.toString(), { ...extraData, isFromCallFunc: true }, targetType, SymbolTypeFlag.typetime);
38✔
137
            }
138
        }
139

140
        // add this function to be available through callfunc
141
        this.callFuncMemberTable.addSymbol(name, data, funcType, flags);
45✔
142
    }
143

144
    getCallFuncTable() {
145
        return this.callFuncMemberTable;
3✔
146
    }
147

148
    getCallFuncType(name: string, options: GetSymbolTypeOptions) {
149
        const callFuncType = this.callFuncMemberTable.getSymbolType(name, options);
237✔
150

151
        const addAssociatedTypesTableAsSiblingToMemberTable = (type: BscType) => {
234✔
152
            if (isReferenceType(type) &&
435✔
153
                !type.isResolvable()) {
154
                // This param or return type is a reference - make sure the associated types are included
155
                type.tableProvider().addSibling(this.callFuncAssociatedTypesTable);
4✔
156

157
                // add this as a sister table to member tables too!
158
                const memberTable: SymbolTable = type.getMemberTable();
4✔
159
                if (memberTable.getAllSymbols) {
4!
160
                    for (const memberSymbol of memberTable.getAllSymbols(SymbolTypeFlag.runtime)) {
4✔
161
                        addAssociatedTypesTableAsSiblingToMemberTable(memberSymbol?.type);
6!
162
                    }
163
                }
164

165
            }
166
        };
167

168
        if (isTypedFunctionType(callFuncType)) {
234✔
169
            const typesToCheck = [...callFuncType.params.map(p => p.type), callFuncType.returnType];
229✔
170

171
            for (const type of typesToCheck) {
229✔
172
                addAssociatedTypesTableAsSiblingToMemberTable(type);
429✔
173
            }
174
        }
175

176
        return callFuncType;
234✔
177
    }
178
}
179

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

© 2025 Coveralls, Inc