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

rokucommunity / brighterscript / 27160110400

08 Jun 2026 06:58PM UTC coverage: 86.985%. First build
27160110400

Pull #1729

github

web-flow
Merge aee89995f into 285d34446
Pull Request #1729: First Validation performance improvements

16023 of 19450 branches covered (82.38%)

Branch coverage included in aggregate %.

48 of 57 new or added lines in 6 files covered. (84.21%)

16738 of 18213 relevant lines covered (91.9%)

27457.12 hits per line

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

88.46
/src/astUtils/reflection.ts
1
import type { Body, AssignmentStatement, Block, EmptyStatement, ExpressionStatement, FunctionStatement, IfStatement, IncrementStatement, PrintStatement, GotoStatement, LabelStatement, ReturnStatement, EndStatement, StopStatement, ForStatement, ForEachStatement, WhileStatement, DottedSetStatement, IndexedSetStatement, LibraryStatement, NamespaceStatement, ImportStatement, ClassStatement, InterfaceFieldStatement, InterfaceMethodStatement, InterfaceStatement, EnumStatement, EnumMemberStatement, TryCatchStatement, CatchStatement, ThrowStatement, MethodStatement, FieldStatement, ConstStatement, ContinueStatement, DimStatement, TypecastStatement, AliasStatement, AugmentedAssignmentStatement, ConditionalCompileConstStatement, ConditionalCompileErrorStatement, ConditionalCompileStatement, ExitStatement, TypeStatement } from '../parser/Statement';
2
import type { LiteralExpression, BinaryExpression, CallExpression, FunctionExpression, DottedGetExpression, XmlAttributeGetExpression, IndexedGetExpression, GroupingExpression, EscapedCharCodeLiteralExpression, ArrayLiteralExpression, AALiteralExpression, UnaryExpression, VariableExpression, SourceLiteralExpression, NewExpression, CallfuncExpression, TemplateStringQuasiExpression, TemplateStringExpression, TaggedTemplateStringExpression, AnnotationExpression, FunctionParameterExpression, AAMemberExpression, AAIndexedMemberExpression, TernaryExpression, NullCoalescingExpression, PrintSeparatorExpression, TypecastExpression, TypedArrayExpression, TypeExpression, InlineInterfaceMemberExpression, InlineInterfaceExpression, TypedFunctionTypeExpression } from '../parser/Expression';
3
import type { BrsFile } from '../files/BrsFile';
4
import type { XmlFile } from '../files/XmlFile';
5
import type { BsDiagnostic, TypedefProvider } from '../interfaces';
6
import type { InvalidType } from '../types/InvalidType';
7
import type { VoidType } from '../types/VoidType';
8
import { InternalWalkMode } from './visitors';
1✔
9
import type { TypedFunctionType } from '../types/TypedFunctionType';
10
import type { FunctionType } from '../types/FunctionType';
11
import type { StringType } from '../types/StringType';
12
import type { BooleanType } from '../types/BooleanType';
13
import type { IntegerType } from '../types/IntegerType';
14
import type { LongIntegerType } from '../types/LongIntegerType';
15
import type { FloatType } from '../types/FloatType';
16
import type { DoubleType } from '../types/DoubleType';
17
import type { ClassType } from '../types/ClassType';
18
import type { Scope } from '../Scope';
19
import type { XmlScope } from '../XmlScope';
20
import type { DynamicType } from '../types/DynamicType';
21
import type { InterfaceType } from '../types/InterfaceType';
22
import type { ObjectType } from '../types/ObjectType';
23
import type { AstNode, Expression, Statement } from '../parser/AstNode';
24
import type { AssetFile } from '../files/AssetFile';
25
import { AstNodeKind } from '../parser/AstNode';
1✔
26
import type { TypePropertyReferenceType, ReferenceType, BinaryOperatorReferenceType, ArrayDefaultTypeReferenceType, AnyReferenceType, ParamTypeFromValueReferenceType, ReferenceTypeWithDefault } from '../types/ReferenceType';
27
import type { EnumMemberType, EnumType } from '../types/EnumType';
28
import type { UnionType } from '../types/UnionType';
29
import type { UninitializedType } from '../types/UninitializedType';
30
import type { ArrayType } from '../types/ArrayType';
31
import type { InheritableType } from '../types/InheritableType';
32
import type { CallFuncableType } from '../types/CallFuncableType';
33
import { BscTypeKind } from '../types/BscTypeKind';
1✔
34
import type { NamespaceType } from '../types/NamespaceType';
35
import type { BaseFunctionType } from '../types/BaseFunctionType';
36
import type { BscFile } from '../files/BscFile';
37
import type { ComponentType } from '../types/ComponentType';
38
import type { AssociativeArrayType } from '../types/AssociativeArrayType';
39
import { TokenKind } from '../lexer/TokenKind';
1✔
40
import type { Program } from '../Program';
41
import type { Project } from '../lsp/Project';
42
import type { IntersectionType } from '../types/IntersectionType';
43
import type { TypeStatementType } from '../types/TypeStatementType';
44
import type { BscType } from '../types/BscType';
45
import type { SymbolTable } from '../SymbolTable';
46

47

48
// File reflection
49
export function isBrsFile(file: BscFile | undefined): file is BrsFile {
1✔
50
    return file?.constructor.name === 'BrsFile';
115,934✔
51
}
52

53
export function isXmlFile(file: (BscFile | XmlFile | undefined)): file is XmlFile {
1✔
54
    return file?.constructor.name === 'XmlFile';
28,082✔
55
}
56

57
export function isAssetFile(file: (BscFile | AssetFile | undefined)): file is AssetFile {
1✔
58
    return file?.constructor.name === 'AssetFile';
12!
59
}
60

61
export function isBscFile(file: (BscFile | BscFile | XmlFile | AssetFile | undefined)): file is BscFile {
1✔
62
    return isBrsFile(file) || isXmlFile(file) || isAssetFile(file);
×
63
}
64

65

66
export function isXmlScope(scope: (Scope | undefined)): scope is XmlScope {
1✔
67
    return scope?.constructor.name === 'XmlScope';
3,608!
68
}
69

70

71
export function isProgram(arg: any): arg is Program {
1✔
72
    return arg?.constructor.name === 'Program';
×
73
}
74

75
export function isProject(arg: any): arg is Project {
1✔
76
    return arg?.constructor.name === 'Project';
×
77
}
78

79

80
// Statements reflection
81

82
/**
83
 * Determine if the variablvalue is a descendent of the Statement base class.
84
 * Due to performance restrictions, this expects all statements to
85
 * directly extend Statement or FunctionStatement,
86
 * so it only checks the immediate parent's class name.
87
 */
88
export function isStatement(element: AstNode | undefined): element is Statement {
1✔
89
    // eslint-disable-next-line no-bitwise
90
    return !!(element && element.visitMode & InternalWalkMode.visitStatements);
42,450✔
91
}
92

93
export function isBody(element: AstNode | undefined): element is Body {
1✔
94
    return element?.constructor?.name === 'Body';
129,792!
95
}
96
export function isAssignmentStatement(element: AstNode | undefined): element is AssignmentStatement {
1✔
97
    return element?.kind === AstNodeKind.AssignmentStatement;
24,163✔
98
}
99
export function isBlock(element: AstNode | undefined): element is Block {
1✔
100
    return element?.constructor?.name === 'Block';
138,332✔
101
}
102
export function isExpressionStatement(element: AstNode | undefined): element is ExpressionStatement {
1✔
103
    return element?.kind === AstNodeKind.ExpressionStatement;
340!
104
}
105
export function isEmptyStatement(element: AstNode | undefined): element is EmptyStatement {
1✔
NEW
106
    return element?.kind === AstNodeKind.EmptyStatement;
×
107
}
108
/**
109
 * @deprecated use `isEmptyStatement` instead
110
 */
111
export function isCommentStatement(element: AstNode | undefined): element is EmptyStatement {
1✔
NEW
112
    return isEmptyStatement(element);
×
113
}
114
export function isExitStatement(element: AstNode | undefined): element is ExitStatement {
1✔
115
    return element?.kind === AstNodeKind.ExitStatement;
6!
116
}
117
export function isFunctionStatement(element: AstNode | undefined): element is FunctionStatement {
1✔
118
    return element?.kind === AstNodeKind.FunctionStatement;
39,075✔
119
}
120
export function isIfStatement(element: AstNode | undefined): element is IfStatement {
1✔
121
    return element?.kind === AstNodeKind.IfStatement;
5,373✔
122
}
123
export function isIncrementStatement(element: AstNode | undefined): element is IncrementStatement {
1✔
124
    return element?.kind === AstNodeKind.IncrementStatement;
8!
125
}
126
export function isPrintStatement(element: AstNode | undefined): element is PrintStatement {
1✔
127
    return element?.kind === AstNodeKind.PrintStatement;
429!
128
}
129
export function isGotoStatement(element: AstNode | undefined): element is GotoStatement {
1✔
130
    return element?.kind === AstNodeKind.GotoStatement;
2!
131
}
132
export function isLabelStatement(element: AstNode | undefined): element is LabelStatement {
1✔
133
    return element?.kind === AstNodeKind.LabelStatement;
2!
134
}
135
export function isReturnStatement(element: AstNode | undefined): element is ReturnStatement {
1✔
136
    return element?.kind === AstNodeKind.ReturnStatement;
854!
137
}
138
export function isTernaryExpression(element: AstNode | undefined): element is TernaryExpression {
1✔
139
    return element?.constructor?.name === 'TernaryExpression';
15!
140
}
141
export function isNullCoalescingExpression(element: AstNode | undefined): element is NullCoalescingExpression {
1✔
142
    return element?.constructor?.name === 'NullCoalescingExpression';
10!
143
}
144
export function isEndStatement(element: AstNode | undefined): element is EndStatement {
1✔
145
    return element?.kind === AstNodeKind.EndStatement;
2!
146
}
147
export function isStopStatement(element: AstNode | undefined): element is StopStatement {
1✔
148
    return element?.kind === AstNodeKind.StopStatement;
2!
149
}
150
export function isForStatement(element: AstNode | undefined): element is ForStatement {
1✔
151
    return element?.kind === AstNodeKind.ForStatement;
1,497✔
152
}
153
export function isForEachStatement(element: AstNode | undefined): element is ForEachStatement {
1✔
154
    return element?.kind === AstNodeKind.ForEachStatement;
654✔
155
}
156
export function isWhileStatement(element: AstNode | undefined): element is WhileStatement {
1✔
157
    return element?.kind === AstNodeKind.WhileStatement;
153✔
158
}
159
export function isDimStatement(element: AstNode | undefined): element is DimStatement {
1✔
160
    return element?.constructor?.name === 'DimStatement';
8!
161
}
162
export function isDottedSetStatement(element: AstNode | undefined): element is DottedSetStatement {
1✔
163
    return element?.kind === AstNodeKind.DottedSetStatement;
309!
164
}
165
export function isIndexedSetStatement(element: AstNode | undefined): element is IndexedSetStatement {
1✔
166
    return element?.kind === AstNodeKind.IndexedSetStatement;
303!
167
}
168
export function isLibraryStatement(element: AstNode | undefined): element is LibraryStatement {
1✔
169
    return element?.kind === AstNodeKind.LibraryStatement;
3,154!
170
}
171
export function isNamespaceStatement(element: AstNode | undefined): element is NamespaceStatement {
1✔
172
    return element?.kind === AstNodeKind.NamespaceStatement;
258,628✔
173
}
174
export function isClassStatement(element: AstNode | undefined): element is ClassStatement {
1✔
175
    return element?.kind === AstNodeKind.ClassStatement;
16,780!
176
}
177
export function isImportStatement(element: AstNode | undefined): element is ImportStatement {
1✔
178
    return element?.kind === AstNodeKind.ImportStatement;
3,589!
179
}
180
export function isMethodStatement(element: AstNode | undefined): element is MethodStatement {
1✔
181
    return element?.kind === AstNodeKind.MethodStatement;
15,444✔
182
}
183
export function isFieldStatement(element: AstNode | undefined): element is FieldStatement {
1✔
184
    return element?.kind === AstNodeKind.FieldStatement;
1,618✔
185
}
186
export function isInterfaceStatement(element: AstNode | undefined): element is InterfaceStatement {
1✔
187
    return element?.kind === AstNodeKind.InterfaceStatement;
5,237!
188
}
189
export function isInterfaceMethodStatement(element: AstNode | undefined): element is InterfaceMethodStatement {
1✔
190
    return element?.kind === AstNodeKind.InterfaceMethodStatement;
5,848✔
191
}
192
export function isInterfaceFieldStatement(element: AstNode | undefined): element is InterfaceFieldStatement {
1✔
193
    return element?.kind === AstNodeKind.InterfaceFieldStatement;
416!
194
}
195
export function isMemberField(element: AstNode | undefined): element is InterfaceFieldStatement | FieldStatement {
1✔
196
    return isFieldStatement(element) || isInterfaceFieldStatement(element);
82✔
197
}
198
export function isMemberMethod(element: AstNode | undefined): element is InterfaceMethodStatement | MethodStatement {
1✔
199
    return isMethodStatement(element) || isInterfaceMethodStatement(element);
×
200
}
201

202
export function isEnumStatement(element: AstNode | undefined): element is EnumStatement {
1✔
203
    return element?.kind === AstNodeKind.EnumStatement;
1,212!
204
}
205
export function isEnumMemberStatement(element: AstNode | undefined): element is EnumMemberStatement {
1✔
206
    return element?.kind === AstNodeKind.EnumMemberStatement;
964!
207
}
208
export function isConstStatement(element: AstNode | undefined): element is ConstStatement {
1✔
209
    return element?.kind === AstNodeKind.ConstStatement;
6,482✔
210
}
211
export function isContinueStatement(element: AstNode | undefined): element is ContinueStatement {
1✔
212
    return element?.kind === AstNodeKind.ContinueStatement;
27!
213
}
214
export function isTryCatchStatement(element: AstNode | undefined): element is TryCatchStatement {
1✔
215
    return element?.kind === AstNodeKind.TryCatchStatement;
139✔
216
}
217
export function isCatchStatement(element: AstNode | undefined): element is CatchStatement {
1✔
218
    return element?.kind === AstNodeKind.CatchStatement;
132✔
219
}
220
export function isThrowStatement(element: AstNode | undefined): element is ThrowStatement {
1✔
221
    return element?.kind === AstNodeKind.ThrowStatement;
6!
222
}
223
export function isConditionalCompileStatement(element: AstNode | undefined): element is ConditionalCompileStatement {
1✔
224
    return element?.kind === AstNodeKind.ConditionalCompileStatement;
5,566✔
225
}
226
export function isConditionalCompileConstStatement(element: AstNode | undefined): element is ConditionalCompileConstStatement {
1✔
227
    return element?.kind === AstNodeKind.ConditionalCompileConstStatement;
95!
228
}
229
export function isConditionalCompileErrorStatement(element: AstNode | undefined): element is ConditionalCompileErrorStatement {
1✔
230
    return element?.kind === AstNodeKind.ConditionalCompileErrorStatement;
91!
231
}
232
export function isAugmentedAssignmentStatement(element: AstNode | undefined): element is AugmentedAssignmentStatement {
1✔
233
    return element?.kind === AstNodeKind.AugmentedAssignmentStatement;
29!
234
}
235
export function isTypecastStatement(element: AstNode | undefined): element is TypecastStatement {
1✔
236
    return element?.constructor?.name === 'TypecastStatement';
6,811✔
237
}
238
export function isAliasStatement(element: AstNode | undefined): element is AliasStatement {
1✔
239
    return element?.constructor?.name === 'AliasStatement';
108,290✔
240
}
241
export function isTypeStatement(element: AstNode | undefined): element is TypeStatement {
1✔
242
    return element?.constructor?.name === 'TypeStatement';
4,304!
243
}
244

245
// Expressions reflection
246
/**
247
 * Determine if the variablvalue is a descendent of the Expression base class.
248
 * Due to performance restrictions, this expects all statements to directly extend Expression,
249
 * so it only checks the immediate parent's class name. For example:
250
 * this will work for StringLiteralExpression -> Expression,
251
 * but will not work CustomStringLiteralExpression -> StringLiteralExpression -> Expression
252
 */
253
export function isExpression(element: AstNode | undefined): element is Expression {
1✔
254
    // eslint-disable-next-line no-bitwise
255
    return !!(element && element.visitMode & InternalWalkMode.visitExpressions);
223✔
256
}
257

258
export function isBinaryExpression(element: AstNode | undefined): element is BinaryExpression {
1✔
259
    return element?.kind === AstNodeKind.BinaryExpression;
39,546!
260
}
261
export function isCallExpression(element: AstNode | undefined): element is CallExpression {
1✔
262
    return element?.kind === AstNodeKind.CallExpression;
59,679✔
263
}
264
export function isFunctionExpression(element: AstNode | undefined): element is FunctionExpression {
1✔
265
    return element?.kind === AstNodeKind.FunctionExpression;
87,285✔
266
}
267
export function isDottedGetExpression(element: AstNode | undefined): element is DottedGetExpression {
1✔
268
    return element?.kind === AstNodeKind.DottedGetExpression;
71,201✔
269
}
270
export function isXmlAttributeGetExpression(element: AstNode | undefined): element is XmlAttributeGetExpression {
1✔
271
    return element?.kind === AstNodeKind.XmlAttributeGetExpression;
15,945!
272
}
273
export function isIndexedGetExpression(element: AstNode | undefined): element is IndexedGetExpression {
1✔
274
    return element?.kind === AstNodeKind.IndexedGetExpression;
16,734!
275
}
276
export function isGroupingExpression(element: AstNode | undefined): element is GroupingExpression {
1✔
277
    return element?.kind === AstNodeKind.GroupingExpression;
2,167!
278
}
279
export function isLiteralExpression(element: AstNode | undefined): element is LiteralExpression {
1✔
280
    return element?.kind === AstNodeKind.LiteralExpression;
3,334✔
281
}
282
export function isEscapedCharCodeLiteralExpression(element: AstNode | undefined): element is EscapedCharCodeLiteralExpression {
1✔
283
    return element?.kind === AstNodeKind.EscapedCharCodeLiteralExpression;
19!
284
}
285
export function isArrayLiteralExpression(element: AstNode | undefined): element is ArrayLiteralExpression {
1✔
286
    return element?.kind === AstNodeKind.ArrayLiteralExpression;
23!
287
}
288
export function isAALiteralExpression(element: AstNode | undefined): element is AALiteralExpression {
1✔
289
    return element?.kind === AstNodeKind.AALiteralExpression;
26!
290
}
291
export function isAAMemberExpression(element: AstNode | undefined): element is AAMemberExpression {
1✔
292
    return element?.kind === AstNodeKind.AAMemberExpression;
1,424!
293
}
294
export function isAAIndexedMemberExpression(element: AstNode | undefined): element is AAIndexedMemberExpression {
1✔
295
    return element?.constructor.name === 'AAIndexedMemberExpression';
88!
296
}
297
export function isUnaryExpression(element: AstNode | undefined): element is UnaryExpression {
1✔
298
    return element?.kind === AstNodeKind.UnaryExpression;
13,888✔
299
}
300
export function isVariableExpression(element: AstNode | undefined): element is VariableExpression {
1✔
301
    return element?.kind === AstNodeKind.VariableExpression;
45,455✔
302
}
303
export function isSourceLiteralExpression(element: AstNode | undefined): element is SourceLiteralExpression {
1✔
304
    return element?.kind === AstNodeKind.SourceLiteralExpression;
2!
305
}
306
export function isNewExpression(element: AstNode | undefined): element is NewExpression {
1✔
307
    return element?.kind === AstNodeKind.NewExpression;
22,157!
308
}
309
export function isCallfuncExpression(element: AstNode | undefined): element is CallfuncExpression {
1✔
310
    return element?.kind === AstNodeKind.CallfuncExpression;
26,243!
311
}
312
export function isTemplateStringQuasiExpression(element: AstNode | undefined): element is TemplateStringQuasiExpression {
1✔
313
    return element?.kind === AstNodeKind.TemplateStringQuasiExpression;
14!
314
}
315
export function isTemplateStringExpression(element: AstNode | undefined): element is TemplateStringExpression {
1✔
316
    return element?.kind === AstNodeKind.TemplateStringExpression;
26!
317
}
318
export function isTaggedTemplateStringExpression(element: AstNode | undefined): element is TaggedTemplateStringExpression {
1✔
319
    return element?.kind === AstNodeKind.TaggedTemplateStringExpression;
22!
320
}
321
export function isFunctionParameterExpression(element: AstNode | undefined): element is FunctionParameterExpression {
1✔
322
    return element?.kind === AstNodeKind.FunctionParameterExpression;
36,759✔
323
}
324
export function isAnnotationExpression(element: AstNode | undefined): element is AnnotationExpression {
1✔
325
    return element?.kind === AstNodeKind.AnnotationExpression;
73,364!
326
}
327
export function isTypedefProvider(element: any): element is TypedefProvider {
1✔
328
    return 'getTypedef' in element;
125✔
329
}
330
export function isTypeExpression(element: any): element is TypeExpression {
1✔
331
    return element?.kind === AstNodeKind.TypeExpression;
70,999!
332
}
333
export function isTypecastExpression(element: any): element is TypecastExpression {
1✔
334
    return element?.kind === AstNodeKind.TypecastExpression;
63!
335
}
336
export function isTypedArrayExpression(element: any): element is TypedArrayExpression {
1✔
337
    return element?.kind === AstNodeKind.TypedArrayExpression;
36,441!
338
}
339
export function isPrintSeparatorExpression(element: any): element is PrintSeparatorExpression {
1✔
340
    return element?.kind === AstNodeKind.PrintSeparatorExpression;
72!
341
}
342
export function isInlineInterfaceExpression(element: any): element is InlineInterfaceExpression {
1✔
343
    return element?.kind === AstNodeKind.InlineInterfaceExpression;
4!
344
}
345
export function isInlineInterfaceMemberExpression(element: any): element is InlineInterfaceMemberExpression {
1✔
346
    return element?.kind === AstNodeKind.InlineInterfaceMemberExpression;
×
347
}
348
export function isTypedFunctionTypeExpression(element: any): element is TypedFunctionTypeExpression {
1✔
349
    return element?.kind === AstNodeKind.TypedFunctionTypeExpression;
1,402!
350
}
351

352
// BscType reflection
353
export function isStringType(value: any): value is StringType {
1✔
354
    return value?.kind === BscTypeKind.StringType;
950,388!
355
}
356
export function isRoStringType(value: any): value is InterfaceType {
1✔
357
    return isBuiltInType(value, 'roString');
2,076✔
358
}
359
export function isStringTypeLike(value: any): value is StringType | InterfaceType {
1✔
360
    return isStringType(value) || isRoStringType(value) || isCompoundTypeOf(value, isStringTypeLike);
3,579✔
361
}
362

363
export function isTypedFunctionType(value: any): value is TypedFunctionType {
1✔
364
    return value?.kind === BscTypeKind.TypedFunctionType;
961,023✔
365
}
366

367
export function isTypedFunctionTypeLike(value: any): value is TypedFunctionType | TypeStatementType | UnionType {
1✔
368
    return isTypedFunctionType(value) || isTypeStatementTypeOf(value, isTypedFunctionTypeLike) || isUnionTypeOf(value, isTypedFunctionTypeLike);
950,984✔
369
}
370

371
export function isFunctionType(value: any): value is FunctionType {
1✔
372
    return value?.kind === BscTypeKind.FunctionType;
956,190✔
373
}
374
export function isRoFunctionType(value: any): value is InterfaceType {
1✔
375
    return value?.kind === BscTypeKind.RoFunctionType || isBuiltInType(value, 'roFunction');
956,122✔
376
}
377
export function isFunctionTypeLike(value: any): value is FunctionType | InterfaceType {
1✔
378
    return isFunctionType(value) || isRoFunctionType(value) || isCompoundTypeOf(value, isFunctionTypeLike);
956,190✔
379
}
380

381
export function isBooleanType(value: any): value is BooleanType {
1✔
382
    return value?.kind === BscTypeKind.BooleanType;
948,847!
383
}
384
export function isRoBooleanType(value: any): value is InterfaceType {
1✔
385
    return isBuiltInType(value, 'roBoolean');
2,162✔
386
}
387
export function isBooleanTypeLike(value: any): value is BooleanType | InterfaceType {
1✔
388
    return isBooleanType(value) || isRoBooleanType(value) || isCompoundTypeOf(value, isBooleanTypeLike);
2,474✔
389
}
390

391
export function isIntegerType(value: any): value is IntegerType {
1✔
392
    return value?.kind === BscTypeKind.IntegerType;
953,253!
393
}
394
export function isRoIntType(value: any): value is LongIntegerType {
1✔
395
    return isBuiltInType(value, 'roInt');
3,322✔
396
}
397
export function isIntegerTypeLike(value: any): value is IntegerType | InterfaceType {
1✔
398
    return isIntegerType(value) || isRoIntType(value) || isCompoundTypeOf(value, isIntegerTypeLike);
5,939✔
399
}
400

401
export function isLongIntegerType(value: any): value is LongIntegerType {
1✔
402
    return value?.kind === BscTypeKind.LongIntegerType;
951,140!
403
}
404
export function isRoLongIntegerType(value: any): value is InterfaceType {
1✔
405
    return isBuiltInType(value, 'roLongInteger');
4,489✔
406
}
407
export function isLongIntegerTypeLike(value: any): value is LongIntegerType | InterfaceType {
1✔
408
    return isLongIntegerType(value) || isRoLongIntegerType(value) || isCompoundTypeOf(value, isLongIntegerTypeLike);
4,674✔
409
}
410

411
export function isFloatType(value: any): value is FloatType {
1✔
412
    return value?.kind === BscTypeKind.FloatType;
951,141!
413
}
414
export function isRoFloatType(value: any): value is InterfaceType {
1✔
415
    return isBuiltInType(value, 'roFloat');
4,180✔
416
}
417
export function isFloatTypeLike(value: any): value is FloatType | InterfaceType {
1✔
418
    return isFloatType(value) || isRoFloatType(value) || isCompoundTypeOf(value, isFloatTypeLike);
4,731✔
419
}
420

421
export function isDoubleType(value: any): value is DoubleType {
1✔
422
    return value?.kind === BscTypeKind.DoubleType;
950,465!
423
}
424
export function isRoDoubleType(value: any): value is InterfaceType {
1✔
425
    return isBuiltInType(value, 'roDouble');
4,086✔
426
}
427
export function isDoubleTypeLike(value: any): value is DoubleType | InterfaceType {
1✔
428
    return isDoubleType(value) || isRoDoubleType(value) || isCompoundTypeOf(value, isDoubleTypeLike);
4,151✔
429
}
430

431
export function isInvalidType(value: any): value is InvalidType {
1✔
432
    return value?.kind === BscTypeKind.InvalidType;
955,677✔
433
}
434
export function isRoInvalidType(value: any): value is InterfaceType {
1✔
435
    return isBuiltInType(value, 'roInvalid');
1,642✔
436
}
437
export function isInvalidTypeLike(value: any): value is InvalidType | InterfaceType {
1✔
438
    return isInvalidType(value) || isRoInvalidType(value) || isCompoundTypeOf(value, isInvalidTypeLike);
1,710✔
439
}
440

441
export function isVoidType(value: any): value is VoidType {
1✔
442
    return value?.kind === BscTypeKind.VoidType;
318,274✔
443
}
444
export function isClassType(value: any): value is ClassType {
1✔
445
    return value?.kind === BscTypeKind.ClassType;
41,823✔
446
}
447
export function isComponentType(value: any): value is ComponentType {
1✔
448
    return value?.kind === BscTypeKind.ComponentType;
297,631✔
449
}
450
export function isDynamicType(value: any): value is DynamicType {
1✔
451
    return value?.kind === BscTypeKind.DynamicType;
1,263,772✔
452
}
453
export function isInterfaceType(value: any): value is InterfaceType {
1✔
454
    return value?.kind === BscTypeKind.InterfaceType;
1,919,060✔
455
}
456
export function isObjectType(value: any): value is ObjectType {
1✔
457
    return value?.kind === BscTypeKind.ObjectType;
950,170✔
458
}
459
export function isReferenceType(value: any): value is ReferenceType {
1✔
460
    return value?.__reflection?.name === 'ReferenceType';
628,266✔
461
}
462
export function isEnumType(value: any): value is EnumType {
1✔
463
    return value?.kind === BscTypeKind.EnumType;
6,683✔
464
}
465
export function isEnumMemberType(value: any): value is EnumMemberType {
1✔
466
    return value?.kind === BscTypeKind.EnumMemberType;
944,366!
467
}
468
export function isTypePropertyReferenceType(value: any): value is TypePropertyReferenceType {
1✔
469
    return value?.__reflection?.name === 'TypePropertyReferenceType';
1,798!
470
}
471
export function isBinaryOperatorReferenceType(value: any): value is BinaryOperatorReferenceType {
1✔
472
    return value?.__reflection?.name === 'BinaryOperatorReferenceType';
6!
473
}
474
export function isArrayDefaultTypeReferenceType(value: any): value is ArrayDefaultTypeReferenceType {
1✔
475
    return value?.__reflection?.name === 'ArrayDefaultTypeReferenceType';
1,771!
476
}
477
export function isParamTypeFromValueReferenceType(value: any): value is ParamTypeFromValueReferenceType {
1✔
478
    return value?.__reflection?.name === 'ParamTypeFromValueReferenceType';
584!
479
}
480
export function isReferenceTypeWithDefault(value: any): value is ReferenceTypeWithDefault {
1✔
481
    return value?.__reflection?.name === 'ReferenceTypeWithDefault';
×
482
}
483
export function isNamespaceType(value: any): value is NamespaceType {
1✔
484
    return value?.kind === BscTypeKind.NamespaceType;
19,647✔
485
}
486
export function isUnionType(value: any): value is UnionType {
1✔
487
    return value?.kind === BscTypeKind.UnionType;
3,543,533✔
488
}
489
export function isIntersectionType(value: any): value is IntersectionType {
1✔
490
    return value?.kind === BscTypeKind.IntersectionType;
1,335,938✔
491
}
492
export function isUninitializedType(value: any): value is UninitializedType {
1✔
493
    return value?.kind === BscTypeKind.UninitializedType;
2,469✔
494
}
495
export function isArrayType(value: any): value is ArrayType {
1✔
496
    return value?.kind === BscTypeKind.ArrayType;
947,108✔
497
}
498
export function isAssociativeArrayType(value: any): value is AssociativeArrayType {
1✔
499
    return value?.kind === BscTypeKind.AssociativeArrayType;
939,609✔
500
}
501
export function isTypeStatementType(value: any): value is TypeStatementType {
1✔
502
    return value?.kind === BscTypeKind.TypeStatementType;
3,855,321✔
503
}
504

505
export function isInheritableType(target): target is InheritableType {
1✔
506
    return isClassType(target) || isInterfaceType(target) || isComponentType(target);
4,773✔
507
}
508

509
export function isCallFuncableType(target): target is CallFuncableType {
1✔
510
    return isInterfaceType(target) || isComponentType(target) || isCompoundTypeOf(target, isCallFuncableType);
211✔
511
}
512

513
export function isCallableType(target): target is BaseFunctionType {
1✔
514
    return isFunctionTypeLike(target) ||
956,082✔
515
        isTypedFunctionTypeLike(target) ||
516
        isTypeStatementTypeOf(target, isCallableType) ||
517
        isUnionTypeOf(target, isCallableType) ||
518
        isObjectType(target) ||
519
        (isDynamicType(target) && !isAnyReferenceType(target));
520
}
521

522
export function isAnyReferenceType(target): target is AnyReferenceType {
1✔
523
    const name = target?.__reflection?.name;
2,851,512✔
524
    return name === 'ReferenceType' || name === 'TypePropertyReferenceType' || name === 'BinaryOperatorReferenceType' || name === 'ArrayDefaultTypeReferenceType' || name === 'ParamTypeFromValueReferenceType' || name === 'ReferenceTypeWithDefault';
2,851,512✔
525
}
526

527
export function isNumberType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | InterfaceType {
1✔
528
    return isIntegerType(value) ||
2,178✔
529
        isLongIntegerType(value) ||
530
        isFloatType(value) ||
531
        isDoubleType(value);
532
}
533

534
export function isNumberTypeLike(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | InterfaceType {
1✔
535
    return isIntegerTypeLike(value) ||
5,171✔
536
        isLongIntegerTypeLike(value) ||
537
        isFloatTypeLike(value) ||
538
        isDoubleTypeLike(value) ||
539
        isCompoundTypeOf(value, isNumberTypeLike);
540
}
541

542
export function isPrimitiveType(value: any = false): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType | InterfaceType {
1✔
543
    return isNumberType(value) ||
2,157✔
544
        isBooleanType(value) ||
545
        isStringType(value);
546
}
547

548
export function isPrimitiveTypeLike(value: any = false): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType | InterfaceType {
1!
549
    return isNumberTypeLike(value) ||
×
550
        isBooleanTypeLike(value) ||
551
        isStringTypeLike(value) ||
552
        isTypeStatementTypeOf(value, isPrimitiveTypeLike);
553
}
554

555
export function isAssociativeArrayTypeLike(value: any): value is AssociativeArrayType | InterfaceType {
1✔
556
    return value?.kind === BscTypeKind.AssociativeArrayType || isBuiltInType(value, 'roAssociativeArray') || isCompoundTypeOf(value, isAssociativeArrayTypeLike);
842!
557
}
558

559
export function isArrayTypeLike(value: any): value is ArrayType | InterfaceType {
1✔
560
    return value?.kind === BscTypeKind.ArrayType || isBuiltInType(value, 'roArray') || isCompoundTypeOf(value, isArrayTypeLike);
163!
561
}
562

563
export function isCallFuncableTypeLike(target): target is BscType & { callFuncMemberTable: SymbolTable } {
1✔
564
    return isCallFuncableType(target) || isCompoundTypeOf(target, isCallFuncableTypeLike);
143✔
565
}
566

567
export function isBuiltInType(value: any, name: string): value is InterfaceType {
1✔
568
    return (isInterfaceType(value) && value.name.toLowerCase() === name.toLowerCase() && value.isBuiltIn) ||
974,560✔
569
        (isTypeStatementType(value) && isBuiltInType(value.wrappedType, name));
570
}
571

572
const nativeTypeKinds = [
1✔
573
    BscTypeKind.DynamicType,
574
    BscTypeKind.ObjectType,
575
    BscTypeKind.VoidType,
576
    BscTypeKind.FunctionType
577
];
578
export function isNativeType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType | VoidType | DynamicType | ObjectType | FunctionType | InterfaceType {
1✔
579
    return isPrimitiveType(value) || nativeTypeKinds.includes(value?.kind);
354✔
580
}
581

582
export function isTypeStatementTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
583
    return isTypeStatementType(value) && typeGuard(value.wrappedType);
2,866,797✔
584
}
585

586
export function isUnionTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
587
    return isUnionType(value) && value.types.every(typeGuard);
2,866,895✔
588
}
589
export function isIntersectionTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
590
    return isIntersectionType(value) && value.types.some(typeGuard);
976,113✔
591
}
592

593
export function isCompoundTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
594
    return isTypeStatementTypeOf(value, typeGuard) ||
976,175✔
595
        isUnionTypeOf(value, typeGuard) ||
596
        isIntersectionTypeOf(value, typeGuard);
597
}
598

599
export function isCompoundType(value: any): value is UnionType | IntersectionType {
1✔
600
    return isUnionType(value) || isIntersectionType(value);
4,711✔
601
}
602

603
export function isIterableType(value: any): boolean {
1✔
604
    if (isDynamicType(value) || isObjectType(value)) {
22!
605
        return true;
×
606
    }
607
    if (isArrayTypeLike(value) || isAssociativeArrayTypeLike(value)) {
22✔
608
        return true;
11✔
609
    }
610
    if (isCompoundTypeOf(value, isIterableType)) {
11✔
611
        return true;
2✔
612
    }
613
    if (isBuiltInType(value, 'roByteArray') || isBuiltInType(value, 'roList') || isBuiltInType(value, 'roXMLList') || isBuiltInType(value, 'roMessagePort')) {
9✔
614
        return true;
7✔
615
    }
616
    return false;
2✔
617
}
618

619
// Literal reflection
620

621
export function isLiteralInvalid(value: any): value is LiteralExpression & { type: InvalidType } {
1✔
622
    return isLiteralExpression(value) && value.tokens.value.kind === TokenKind.Invalid;
6✔
623
}
624
export function isLiteralBoolean(value: any): value is LiteralExpression & { type: BooleanType } {
1✔
625
    return isLiteralExpression(value) && isBooleanType(value.getType());
37✔
626
}
627
export function isLiteralString(value: any): value is LiteralExpression & { type: StringType } {
1✔
628
    return isLiteralExpression(value) && isStringType(value.getType());
252✔
629
}
630
export function isLiteralNumber(value: any): value is LiteralExpression & { type: IntegerType | LongIntegerType | FloatType | DoubleType } {
1✔
631
    return isLiteralExpression(value) && isNumberType(value.getType());
32✔
632
}
633
export function isLiteralInteger(value: any): value is LiteralExpression & { type: IntegerType } {
1✔
634
    return isLiteralExpression(value) && isIntegerType(value.getType());
5✔
635
}
636
export function isLiteralLongInteger(value: any): value is LiteralExpression & { type: LongIntegerType } {
1✔
637
    return isLiteralExpression(value) && isLongIntegerType(value.getType());
5✔
638
}
639
export function isLiteralFloat(value: any): value is LiteralExpression & { type: FloatType } {
1✔
640
    return isLiteralExpression(value) && isFloatType(value.getType());
5✔
641
}
642
export function isLiteralDouble(value: any): value is LiteralExpression & { type: DoubleType } {
1✔
643
    return isLiteralExpression(value) && isDoubleType(value.getType());
5✔
644
}
645

646
// Diagnostics
647
export function isBsDiagnostic(value: any): value is BsDiagnostic {
1✔
648
    return value.message;
1,812✔
649
}
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