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

rokucommunity / brighterscript / #13182

14 Oct 2024 03:33PM UTC coverage: 86.831%. Remained the same
#13182

push

web-flow
Merge 7db2dd331 into d585c29e9

11596 of 14122 branches covered (82.11%)

Branch coverage included in aggregate %.

26 of 27 new or added lines in 6 files covered. (96.3%)

112 existing lines in 4 files now uncovered.

12721 of 13883 relevant lines covered (91.63%)

29829.73 hits per line

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

87.87
/src/astUtils/reflection.ts
1
import type { Body, AssignmentStatement, Block, ExpressionStatement, ExitStatement, 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, TypecastStatement, AliasStatement, ConditionalCompileStatement, ConditionalCompileConstStatement, ConditionalCompileErrorStatement, AugmentedAssignmentStatement, DimStatement } 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, TypecastExpression, TypeExpression, TypedArrayExpression, TernaryExpression, NullCoalescingExpression, PrintSeparatorExpression } 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 } 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 { BscTypeKind } from '../types/BscTypeKind';
1✔
33
import type { NamespaceType } from '../types/NamespaceType';
34
import type { BaseFunctionType } from '../types/BaseFunctionType';
35
import type { BscFile } from '../files/BscFile';
36
import type { ComponentType } from '../types/ComponentType';
37
import type { AssociativeArrayType } from '../types/AssociativeArrayType';
38
import { TokenKind } from '../lexer/TokenKind';
1✔
39

40
// File reflection
41
export function isBrsFile(file: BscFile | undefined): file is BrsFile {
1✔
42
    return file?.constructor.name === 'BrsFile';
76,972✔
43
}
44

45
export function isXmlFile(file: (BscFile | XmlFile | undefined)): file is XmlFile {
1✔
46
    return file?.constructor.name === 'XmlFile';
16,302✔
47
}
48

49
export function isAssetFile(file: (BscFile | AssetFile | undefined)): file is AssetFile {
1✔
50
    return file?.constructor.name === 'AssetFile';
11!
51
}
52

53
export function isBscFile(file: (BscFile | BscFile | XmlFile | AssetFile | undefined)): file is BscFile {
1✔
54
    return isBrsFile(file) || isXmlFile(file) || isAssetFile(file);
×
55
}
56

57

58
export function isXmlScope(scope: (Scope | undefined)): scope is XmlScope {
1✔
59
    return scope?.constructor.name === 'XmlScope';
2,116!
60
}
61

62

63
// Statements reflection
64

65
/**
66
 * Determine if the variablvalue is a descendent of the Statement base class.
67
 * Due to performance restrictions, this expects all statements to
68
 * directly extend Statement or FunctionStatement,
69
 * so it only checks the immediate parent's class name.
70
 */
71
export function isStatement(element: AstNode | undefined): element is Statement {
1✔
72
    // eslint-disable-next-line no-bitwise
73
    return !!(element && element.visitMode & InternalWalkMode.visitStatements);
29,205✔
74
}
75

76
export function isBody(element: AstNode | undefined): element is Body {
1✔
77
    return element?.constructor?.name === 'Body';
6,364!
78
}
79
export function isAssignmentStatement(element: AstNode | undefined): element is AssignmentStatement {
1✔
80
    return element?.kind === AstNodeKind.AssignmentStatement;
14,617✔
81
}
82
export function isBlock(element: AstNode | undefined): element is Block {
1✔
83
    return element?.constructor?.name === 'Block';
3,536!
84
}
85
export function isExpressionStatement(element: AstNode | undefined): element is ExpressionStatement {
1✔
86
    return element?.kind === AstNodeKind.ExpressionStatement;
240!
87
}
88
export function isExitStatement(element: AstNode | undefined): element is ExitStatement {
1✔
89
    return element?.kind === AstNodeKind.ExitStatement;
6!
90
}
91
export function isFunctionStatement(element: AstNode | undefined): element is FunctionStatement {
1✔
92
    return element?.kind === AstNodeKind.FunctionStatement;
26,725✔
93
}
94
export function isIfStatement(element: AstNode | undefined): element is IfStatement {
1✔
95
    return element?.kind === AstNodeKind.IfStatement;
3,930✔
96
}
97
export function isIncrementStatement(element: AstNode | undefined): element is IncrementStatement {
1✔
98
    return element?.kind === AstNodeKind.IncrementStatement;
8!
99
}
100
export function isPrintStatement(element: AstNode | undefined): element is PrintStatement {
1✔
101
    return element?.kind === AstNodeKind.PrintStatement;
86!
102
}
103
export function isGotoStatement(element: AstNode | undefined): element is GotoStatement {
1✔
104
    return element?.kind === AstNodeKind.GotoStatement;
2!
105
}
106
export function isLabelStatement(element: AstNode | undefined): element is LabelStatement {
1✔
107
    return element?.kind === AstNodeKind.LabelStatement;
2!
108
}
109
export function isReturnStatement(element: AstNode | undefined): element is ReturnStatement {
1✔
110
    return element?.kind === AstNodeKind.ReturnStatement;
543!
111
}
112
export function isTernaryExpression(element: AstNode | undefined): element is TernaryExpression {
1✔
113
    return element?.constructor?.name === 'TernaryExpression';
15!
114
}
115
export function isNullCoalescingExpression(element: AstNode | undefined): element is NullCoalescingExpression {
1✔
116
    return element?.constructor?.name === 'NullCoalescingExpression';
10!
117
}
118
export function isEndStatement(element: AstNode | undefined): element is EndStatement {
1✔
119
    return element?.kind === AstNodeKind.EndStatement;
2!
120
}
121
export function isStopStatement(element: AstNode | undefined): element is StopStatement {
1✔
122
    return element?.kind === AstNodeKind.StopStatement;
2!
123
}
124
export function isForStatement(element: AstNode | undefined): element is ForStatement {
1✔
125
    return element?.kind === AstNodeKind.ForStatement;
150✔
126
}
127
export function isForEachStatement(element: AstNode | undefined): element is ForEachStatement {
1✔
128
    return element?.kind === AstNodeKind.ForEachStatement;
193✔
129
}
130
export function isWhileStatement(element: AstNode | undefined): element is WhileStatement {
1✔
131
    return element?.kind === AstNodeKind.WhileStatement;
141✔
132
}
133
export function isDimStatement(element: AstNode | undefined): element is DimStatement {
1✔
134
    return element?.constructor?.name === 'DimStatement';
8!
135
}
136
export function isDottedSetStatement(element: AstNode | undefined): element is DottedSetStatement {
1✔
137
    return element?.kind === AstNodeKind.DottedSetStatement;
224!
138
}
139
export function isIndexedSetStatement(element: AstNode | undefined): element is IndexedSetStatement {
1✔
140
    return element?.kind === AstNodeKind.IndexedSetStatement;
221!
141
}
142
export function isLibraryStatement(element: AstNode | undefined): element is LibraryStatement {
1✔
143
    return element?.kind === AstNodeKind.LibraryStatement;
3,968!
144
}
145
export function isNamespaceStatement(element: AstNode | undefined): element is NamespaceStatement {
1✔
146
    return element?.kind === AstNodeKind.NamespaceStatement;
185,341✔
147
}
148
export function isClassStatement(element: AstNode | undefined): element is ClassStatement {
1✔
149
    return element?.kind === AstNodeKind.ClassStatement;
13,005!
150
}
151
export function isImportStatement(element: AstNode | undefined): element is ImportStatement {
1✔
152
    return element?.kind === AstNodeKind.ImportStatement;
4,338!
153
}
154
export function isMethodStatement(element: AstNode | undefined): element is MethodStatement {
1✔
155
    return element?.kind === AstNodeKind.MethodStatement;
10,919✔
156
}
157
export function isFieldStatement(element: AstNode | undefined): element is FieldStatement {
1✔
158
    return element?.kind === AstNodeKind.FieldStatement;
1,382✔
159
}
160
export function isInterfaceStatement(element: AstNode | undefined): element is InterfaceStatement {
1✔
161
    return element?.kind === AstNodeKind.InterfaceStatement;
3,658!
162
}
163
export function isInterfaceMethodStatement(element: AstNode | undefined): element is InterfaceMethodStatement {
1✔
164
    return element?.kind === AstNodeKind.InterfaceMethodStatement;
3,829!
165
}
166
export function isInterfaceFieldStatement(element: AstNode | undefined): element is InterfaceFieldStatement {
1✔
167
    return element?.kind === AstNodeKind.InterfaceFieldStatement;
272!
168
}
169
export function isMemberField(element: AstNode | undefined): element is InterfaceFieldStatement | FieldStatement {
1✔
170
    return isFieldStatement(element) || isInterfaceFieldStatement(element);
53✔
171
}
172
export function isMemberMethod(element: AstNode | undefined): element is InterfaceMethodStatement | MethodStatement {
1✔
173
    return isMethodStatement(element) || isInterfaceMethodStatement(element);
×
174
}
175

176
export function isEnumStatement(element: AstNode | undefined): element is EnumStatement {
1✔
177
    return element?.kind === AstNodeKind.EnumStatement;
876!
178
}
179
export function isEnumMemberStatement(element: AstNode | undefined): element is EnumMemberStatement {
1✔
180
    return element?.kind === AstNodeKind.EnumMemberStatement;
734!
181
}
182
export function isConstStatement(element: AstNode | undefined): element is ConstStatement {
1✔
183
    return element?.kind === AstNodeKind.ConstStatement;
6,219✔
184
}
185
export function isContinueStatement(element: AstNode | undefined): element is ContinueStatement {
1✔
186
    return element?.kind === AstNodeKind.ContinueStatement;
27!
187
}
188
export function isTryCatchStatement(element: AstNode | undefined): element is TryCatchStatement {
1✔
189
    return element?.kind === AstNodeKind.TryCatchStatement;
122✔
190
}
191
export function isCatchStatement(element: AstNode | undefined): element is CatchStatement {
1✔
192
    return element?.kind === AstNodeKind.CatchStatement;
120✔
193
}
194
export function isThrowStatement(element: AstNode | undefined): element is ThrowStatement {
1✔
195
    return element?.kind === AstNodeKind.ThrowStatement;
6!
196
}
197
export function isTypecastStatement(element: AstNode | undefined): element is TypecastStatement {
1✔
198
    return element?.kind === AstNodeKind.TypecastStatement;
3,504✔
199
}
200
export function isConditionalCompileStatement(element: AstNode | undefined): element is ConditionalCompileStatement {
1✔
201
    return element?.kind === AstNodeKind.ConditionalCompileStatement;
3,756✔
202
}
203
export function isConditionalCompileConstStatement(element: AstNode | undefined): element is ConditionalCompileConstStatement {
1✔
204
    return element?.kind === AstNodeKind.ConditionalCompileConstStatement;
47!
205
}
206
export function isConditionalCompileErrorStatement(element: AstNode | undefined): element is ConditionalCompileErrorStatement {
1✔
207
    return element?.kind === AstNodeKind.ConditionalCompileErrorStatement;
43!
208
}
209
export function isAliasStatement(element: AstNode | undefined): element is AliasStatement {
1✔
210
    return element?.kind === AstNodeKind.AliasStatement;
84,807✔
211
}
212
export function isAugmentedAssignmentStatement(element: AstNode | undefined): element is AugmentedAssignmentStatement {
1✔
213
    return element?.kind === AstNodeKind.AugmentedAssignmentStatement;
×
214
}
215

216
// Expressions reflection
217
/**
218
 * Determine if the variablvalue is a descendent of the Expression base class.
219
 * Due to performance restrictions, this expects all statements to directly extend Expression,
220
 * so it only checks the immediate parent's class name. For example:
221
 * this will work for StringLiteralExpression -> Expression,
222
 * but will not work CustomStringLiteralExpression -> StringLiteralExpression -> Expression
223
 */
224
export function isExpression(element: AstNode | undefined): element is Expression {
1✔
225
    // eslint-disable-next-line no-bitwise
226
    return !!(element && element.visitMode & InternalWalkMode.visitExpressions);
175✔
227
}
228

229
export function isBinaryExpression(element: AstNode | undefined): element is BinaryExpression {
1✔
230
    return element?.kind === AstNodeKind.BinaryExpression;
26,071!
231
}
232
export function isCallExpression(element: AstNode | undefined): element is CallExpression {
1✔
233
    return element?.kind === AstNodeKind.CallExpression;
43,144!
234
}
235
export function isFunctionExpression(element: AstNode | undefined): element is FunctionExpression {
1✔
236
    return element?.kind === AstNodeKind.FunctionExpression;
70,683✔
237
}
238
export function isDottedGetExpression(element: AstNode | undefined): element is DottedGetExpression {
1✔
239
    return element?.kind === AstNodeKind.DottedGetExpression;
48,849!
240
}
241
export function isXmlAttributeGetExpression(element: AstNode | undefined): element is XmlAttributeGetExpression {
1✔
242
    return element?.kind === AstNodeKind.XmlAttributeGetExpression;
11,731!
243
}
244
export function isIndexedGetExpression(element: AstNode | undefined): element is IndexedGetExpression {
1✔
245
    return element?.kind === AstNodeKind.IndexedGetExpression;
12,455!
246
}
247
export function isGroupingExpression(element: AstNode | undefined): element is GroupingExpression {
1✔
248
    return element?.kind === AstNodeKind.GroupingExpression;
8!
249
}
250
export function isLiteralExpression(element: AstNode | undefined): element is LiteralExpression {
1✔
251
    return element?.kind === AstNodeKind.LiteralExpression;
2,406✔
252
}
253
export function isEscapedCharCodeLiteralExpression(element: AstNode | undefined): element is EscapedCharCodeLiteralExpression {
1✔
254
    return element?.kind === AstNodeKind.EscapedCharCodeLiteralExpression;
17!
255
}
256
export function isArrayLiteralExpression(element: AstNode | undefined): element is ArrayLiteralExpression {
1✔
257
    return element?.kind === AstNodeKind.ArrayLiteralExpression;
23!
258
}
259
export function isAALiteralExpression(element: AstNode | undefined): element is AALiteralExpression {
1✔
260
    return element?.kind === AstNodeKind.AALiteralExpression;
25!
261
}
262
export function isAAMemberExpression(element: AstNode | undefined): element is AAMemberExpression {
1✔
263
    return element?.kind === AstNodeKind.AAMemberExpression;
458!
264
}
265
export function isUnaryExpression(element: AstNode | undefined): element is UnaryExpression {
1✔
266
    return element?.kind === AstNodeKind.UnaryExpression;
10,546✔
267
}
268
export function isVariableExpression(element: AstNode | undefined): element is VariableExpression {
1✔
269
    return element?.kind === AstNodeKind.VariableExpression;
29,155✔
270
}
271
export function isSourceLiteralExpression(element: AstNode | undefined): element is SourceLiteralExpression {
1✔
272
    return element?.kind === AstNodeKind.SourceLiteralExpression;
2!
273
}
274
export function isNewExpression(element: AstNode | undefined): element is NewExpression {
1✔
275
    return element?.kind === AstNodeKind.NewExpression;
15,385!
276
}
277
export function isCallfuncExpression(element: AstNode | undefined): element is CallfuncExpression {
1✔
278
    return element?.kind === AstNodeKind.CallfuncExpression;
19,872!
279
}
280
export function isTemplateStringQuasiExpression(element: AstNode | undefined): element is TemplateStringQuasiExpression {
1✔
281
    return element?.kind === AstNodeKind.TemplateStringQuasiExpression;
14!
282
}
283
export function isTemplateStringExpression(element: AstNode | undefined): element is TemplateStringExpression {
1✔
284
    return element?.kind === AstNodeKind.TemplateStringExpression;
26!
285
}
286
export function isTaggedTemplateStringExpression(element: AstNode | undefined): element is TaggedTemplateStringExpression {
1✔
287
    return element?.kind === AstNodeKind.TaggedTemplateStringExpression;
22!
288
}
289
export function isFunctionParameterExpression(element: AstNode | undefined): element is FunctionParameterExpression {
1✔
290
    return element?.kind === AstNodeKind.FunctionParameterExpression;
2,266✔
291
}
292
export function isAnnotationExpression(element: AstNode | undefined): element is AnnotationExpression {
1✔
293
    return element?.kind === AstNodeKind.AnnotationExpression;
67,739!
294
}
295
export function isTypedefProvider(element: any): element is TypedefProvider {
1✔
296
    return 'getTypedef' in element;
109✔
297
}
298
export function isTypeExpression(element: any): element is TypeExpression {
1✔
299
    return element?.kind === AstNodeKind.TypeExpression;
44,448!
300
}
301
export function isTypecastExpression(element: any): element is TypecastExpression {
1✔
302
    return element?.kind === AstNodeKind.TypecastExpression;
46!
303
}
304
export function isTypedArrayExpression(element: any): element is TypedArrayExpression {
1✔
305
    return element?.kind === AstNodeKind.TypedArrayExpression;
24,032!
306
}
307
export function isPrintSeparatorExpression(element: any): element is PrintSeparatorExpression {
1✔
308
    return element?.kind === AstNodeKind.PrintSeparatorExpression;
72!
309
}
310

311
// BscType reflection
312
export function isStringType(value: any): value is StringType {
1✔
313
    return value?.kind === BscTypeKind.StringType;
625,875!
314
}
315
export function isTypedFunctionType(value: any): value is TypedFunctionType {
1✔
316
    return value?.kind === BscTypeKind.TypedFunctionType;
638,988✔
317
}
318
export function isFunctionType(value: any): value is FunctionType {
1✔
319
    return value?.kind === BscTypeKind.FunctionType;
633,028✔
320
}
321
export function isBooleanType(value: any): value is BooleanType {
1✔
322
    return value?.kind === BscTypeKind.BooleanType;
624,870!
323
}
324
export function isIntegerType(value: any): value is IntegerType {
1✔
325
    return value?.kind === BscTypeKind.IntegerType;
624,848!
326
}
327
export function isLongIntegerType(value: any): value is LongIntegerType {
1✔
328
    return value?.kind === BscTypeKind.LongIntegerType;
625,241!
329
}
330
export function isFloatType(value: any): value is FloatType {
1✔
331
    return value?.kind === BscTypeKind.FloatType;
625,342!
332
}
333
export function isDoubleType(value: any): value is DoubleType {
1✔
334
    return value?.kind === BscTypeKind.DoubleType;
625,236!
335
}
336
export function isInvalidType(value: any): value is InvalidType {
1✔
337
    return value?.kind === BscTypeKind.InvalidType;
625,166!
338
}
339
export function isVoidType(value: any): value is VoidType {
1✔
340
    return value?.kind === BscTypeKind.VoidType;
381!
341
}
342
export function isClassType(value: any): value is ClassType {
1✔
343
    return value?.kind === BscTypeKind.ClassType;
30,194✔
344
}
345
export function isComponentType(value: any): value is ComponentType {
1✔
346
    return value?.kind === BscTypeKind.ComponentType;
192,409✔
347
}
348
export function isDynamicType(value: any): value is DynamicType {
1✔
349
    return value?.kind === BscTypeKind.DynamicType;
218,269✔
350
}
351
export function isInterfaceType(value: any): value is InterfaceType {
1✔
352
    return value?.kind === BscTypeKind.InterfaceType;
626,763✔
353
}
354
export function isObjectType(value: any): value is ObjectType {
1✔
355
    return value?.kind === BscTypeKind.ObjectType;
1,587✔
356
}
357
export function isReferenceType(value: any): value is ReferenceType {
1✔
358
    return value?.__reflection?.name === 'ReferenceType';
624,483✔
359
}
360
export function isEnumType(value: any): value is EnumType {
1✔
361
    return value?.kind === BscTypeKind.EnumType;
4,720✔
362
}
363
export function isEnumMemberType(value: any): value is EnumMemberType {
1✔
364
    return value?.kind === BscTypeKind.EnumMemberType;
626,181!
365
}
366
export function isTypePropertyReferenceType(value: any): value is TypePropertyReferenceType {
1✔
367
    return value?.__reflection?.name === 'TypePropertyReferenceType';
7!
368
}
369
export function isBinaryOperatorReferenceType(value: any): value is BinaryOperatorReferenceType {
1✔
370
    return value?.__reflection?.name === 'BinaryOperatorReferenceType';
6!
371
}
372
export function isArrayDefaultTypeReferenceType(value: any): value is ArrayDefaultTypeReferenceType {
1✔
373
    return value?.__reflection?.name === 'ArrayDefaultTypeReferenceType';
6!
374
}
375
export function isNamespaceType(value: any): value is NamespaceType {
1✔
376
    return value?.kind === BscTypeKind.NamespaceType;
14,889✔
377
}
378
export function isUnionType(value: any): value is UnionType {
1✔
379
    return value?.kind === BscTypeKind.UnionType;
215,557✔
380
}
381
export function isUninitializedType(value: any): value is UninitializedType {
1✔
UNCOV
382
    return value?.kind === BscTypeKind.UninitializedType;
×
383
}
384
export function isArrayType(value: any): value is ArrayType {
1✔
385
    return value?.kind === BscTypeKind.ArrayType;
624,579!
386
}
387
export function isAssociativeArrayType(value: any): value is AssociativeArrayType {
1✔
388
    return value?.kind === BscTypeKind.AssociativeArrayType;
624,306✔
389
}
390
export function isInheritableType(target): target is InheritableType {
1✔
391
    return isClassType(target) || isInterfaceType(target) || isComponentType(target);
1,838✔
392
}
393

394
export function isCallableType(target): target is BaseFunctionType {
1✔
395
    return isFunctionType(target) || isTypedFunctionType(target);
633,024✔
396
}
397

398
export function isAnyReferenceType(target): target is AnyReferenceType {
1✔
399
    const name = target?.__reflection?.name;
2,241,277✔
400
    return name === 'ReferenceType' || name === 'TypePropertyReferenceType' || name === 'BinaryOperatorReferenceType' || name === 'ArrayDefaultTypeReferenceType';
2,241,277✔
401
}
402

403
const numberTypeKinds = [
1✔
404
    BscTypeKind.IntegerType,
405
    BscTypeKind.LongIntegerType,
406
    BscTypeKind.FloatType,
407
    BscTypeKind.DoubleType
408
];
409
export function isNumberType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType {
1✔
410
    return numberTypeKinds.includes(value?.kind);
2,134!
411
}
412

413
const primitiveTypeKinds = [
1✔
414
    ...numberTypeKinds,
415
    BscTypeKind.BooleanType,
416
    BscTypeKind.StringType
417
];
418
export function isPrimitiveType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType {
1✔
419
    return primitiveTypeKinds.includes(value?.kind);
599✔
420
}
421

422
const nativeTypeKinds = [
1✔
423
    ...primitiveTypeKinds,
424
    BscTypeKind.DynamicType,
425
    BscTypeKind.ObjectType,
426
    BscTypeKind.VoidType,
427
    BscTypeKind.FunctionType
428
];
429
export function isNativeType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType | VoidType | DynamicType | ObjectType | FunctionType {
1✔
430
    return nativeTypeKinds.includes(value?.kind);
199✔
431
}
432

433

434
// Literal reflection
435

436
export function isLiteralInvalid(value: any): value is LiteralExpression & { type: InvalidType } {
1✔
437
    return isLiteralExpression(value) && value.tokens.value.kind === TokenKind.Invalid;
6✔
438
}
439
export function isLiteralBoolean(value: any): value is LiteralExpression & { type: BooleanType } {
1✔
440
    return isLiteralExpression(value) && isBooleanType(value.getType());
37✔
441
}
442
export function isLiteralString(value: any): value is LiteralExpression & { type: StringType } {
1✔
443
    return isLiteralExpression(value) && isStringType(value.getType());
192✔
444
}
445
export function isLiteralNumber(value: any): value is LiteralExpression & { type: IntegerType | LongIntegerType | FloatType | DoubleType } {
1✔
446
    return isLiteralExpression(value) && isNumberType(value.getType());
32✔
447
}
448
export function isLiteralInteger(value: any): value is LiteralExpression & { type: IntegerType } {
1✔
449
    return isLiteralExpression(value) && isIntegerType(value.getType());
5✔
450
}
451
export function isLiteralLongInteger(value: any): value is LiteralExpression & { type: LongIntegerType } {
1✔
452
    return isLiteralExpression(value) && isLongIntegerType(value.getType());
5✔
453
}
454
export function isLiteralFloat(value: any): value is LiteralExpression & { type: FloatType } {
1✔
455
    return isLiteralExpression(value) && isFloatType(value.getType());
5✔
456
}
457
export function isLiteralDouble(value: any): value is LiteralExpression & { type: DoubleType } {
1✔
458
    return isLiteralExpression(value) && isDoubleType(value.getType());
5✔
459
}
460

461
// Diagnostics
462
export function isBsDiagnostic(value: any): value is BsDiagnostic {
1✔
463
    return value.message;
1,256✔
464
}
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