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

rokucommunity / brighterscript / #13071

25 Sep 2024 04:16PM UTC coverage: 86.525% (-1.4%) from 87.933%
#13071

push

web-flow
Merge c610b9e4e into 56dcaaa63

10903 of 13389 branches covered (81.43%)

Branch coverage included in aggregate %.

6936 of 7533 new or added lines in 100 files covered. (92.07%)

83 existing lines in 18 files now uncovered.

12548 of 13714 relevant lines covered (91.5%)

27591.0 hits per line

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

87.96
/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 } 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 } 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';
73,633✔
43
}
44

45
export function isXmlFile(file: (BscFile | XmlFile | undefined)): file is XmlFile {
1✔
46
    return file?.constructor.name === 'XmlFile';
16,096✔
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✔
NEW
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,080!
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);
28,508✔
74
}
75

76
export function isBody(element: AstNode | undefined): element is Body {
1✔
77
    return element?.constructor?.name === 'Body';
6,269!
78
}
79
export function isAssignmentStatement(element: AstNode | undefined): element is AssignmentStatement {
1✔
80
    return element?.kind === AstNodeKind.AssignmentStatement;
14,221✔
81
}
82
export function isBlock(element: AstNode | undefined): element is Block {
1✔
83
    return element?.constructor?.name === 'Block';
3,484!
84
}
85
export function isExpressionStatement(element: AstNode | undefined): element is ExpressionStatement {
1✔
86
    return element?.kind === AstNodeKind.ExpressionStatement;
236!
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,079✔
93
}
94
export function isIfStatement(element: AstNode | undefined): element is IfStatement {
1✔
95
    return element?.kind === AstNodeKind.IfStatement;
3,771✔
96
}
97
export function isIncrementStatement(element: AstNode | undefined): element is IncrementStatement {
1✔
98
    return element?.kind === AstNodeKind.IncrementStatement;
2!
99
}
100
export function isPrintStatement(element: AstNode | undefined): element is PrintStatement {
1✔
101
    return element?.kind === AstNodeKind.PrintStatement;
78!
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;
15!
111
}
112
export function isEndStatement(element: AstNode | undefined): element is EndStatement {
1✔
113
    return element?.kind === AstNodeKind.EndStatement;
2!
114
}
115
export function isStopStatement(element: AstNode | undefined): element is StopStatement {
1✔
116
    return element?.kind === AstNodeKind.StopStatement;
2!
117
}
118
export function isForStatement(element: AstNode | undefined): element is ForStatement {
1✔
119
    return element?.kind === AstNodeKind.ForStatement;
87✔
120
}
121
export function isForEachStatement(element: AstNode | undefined): element is ForEachStatement {
1✔
122
    return element?.kind === AstNodeKind.ForEachStatement;
138✔
123
}
124
export function isWhileStatement(element: AstNode | undefined): element is WhileStatement {
1✔
125
    return element?.kind === AstNodeKind.WhileStatement;
86✔
126
}
127
export function isDottedSetStatement(element: AstNode | undefined): element is DottedSetStatement {
1✔
128
    return element?.kind === AstNodeKind.DottedSetStatement;
212!
129
}
130
export function isIndexedSetStatement(element: AstNode | undefined): element is IndexedSetStatement {
1✔
131
    return element?.kind === AstNodeKind.IndexedSetStatement;
201!
132
}
133
export function isLibraryStatement(element: AstNode | undefined): element is LibraryStatement {
1✔
134
    return element?.kind === AstNodeKind.LibraryStatement;
3,910!
135
}
136
export function isNamespaceStatement(element: AstNode | undefined): element is NamespaceStatement {
1✔
137
    return element?.kind === AstNodeKind.NamespaceStatement;
180,846✔
138
}
139
export function isClassStatement(element: AstNode | undefined): element is ClassStatement {
1✔
140
    return element?.kind === AstNodeKind.ClassStatement;
12,842!
141
}
142
export function isImportStatement(element: AstNode | undefined): element is ImportStatement {
1✔
143
    return element?.kind === AstNodeKind.ImportStatement;
4,280!
144
}
145
export function isMethodStatement(element: AstNode | undefined): element is MethodStatement {
1✔
146
    return element?.kind === AstNodeKind.MethodStatement;
10,622!
147
}
148
export function isFieldStatement(element: AstNode | undefined): element is FieldStatement {
1✔
149
    return element?.kind === AstNodeKind.FieldStatement;
1,373!
150
}
151
export function isInterfaceStatement(element: AstNode | undefined): element is InterfaceStatement {
1✔
152
    return element?.kind === AstNodeKind.InterfaceStatement;
3,609!
153
}
154
export function isInterfaceMethodStatement(element: AstNode | undefined): element is InterfaceMethodStatement {
1✔
155
    return element?.kind === AstNodeKind.InterfaceMethodStatement;
3,666!
156
}
157
export function isInterfaceFieldStatement(element: AstNode | undefined): element is InterfaceFieldStatement {
1✔
158
    return element?.kind === AstNodeKind.InterfaceFieldStatement;
268!
159
}
160
export function isMemberField(element: AstNode | undefined): element is InterfaceFieldStatement | FieldStatement {
1✔
161
    return isFieldStatement(element) || isInterfaceFieldStatement(element);
53✔
162
}
163
export function isMemberMethod(element: AstNode | undefined): element is InterfaceMethodStatement | MethodStatement {
1✔
NEW
164
    return isMethodStatement(element) || isInterfaceMethodStatement(element);
×
165
}
166

167
export function isEnumStatement(element: AstNode | undefined): element is EnumStatement {
1✔
168
    return element?.kind === AstNodeKind.EnumStatement;
869!
169
}
170
export function isEnumMemberStatement(element: AstNode | undefined): element is EnumMemberStatement {
1✔
171
    return element?.kind === AstNodeKind.EnumMemberStatement;
732!
172
}
173
export function isConstStatement(element: AstNode | undefined): element is ConstStatement {
1✔
174
    return element?.kind === AstNodeKind.ConstStatement;
6,203✔
175
}
176
export function isContinueStatement(element: AstNode | undefined): element is ContinueStatement {
1✔
177
    return element?.kind === AstNodeKind.ContinueStatement;
27!
178
}
179
export function isTryCatchStatement(element: AstNode | undefined): element is TryCatchStatement {
1✔
180
    return element?.kind === AstNodeKind.TryCatchStatement;
68✔
181
}
182
export function isCatchStatement(element: AstNode | undefined): element is CatchStatement {
1✔
183
    return element?.kind === AstNodeKind.CatchStatement;
68✔
184
}
185
export function isThrowStatement(element: AstNode | undefined): element is ThrowStatement {
1✔
186
    return element?.kind === AstNodeKind.ThrowStatement;
2!
187
}
188
export function isTypecastStatement(element: AstNode | undefined): element is TypecastStatement {
1✔
189
    return element?.kind === AstNodeKind.TypecastStatement;
3,444✔
190
}
191
export function isConditionalCompileStatement(element: AstNode | undefined): element is ConditionalCompileStatement {
1✔
192
    return element?.kind === AstNodeKind.ConditionalCompileStatement;
3,662✔
193
}
194
export function isConditionalCompileConstStatement(element: AstNode | undefined): element is ConditionalCompileConstStatement {
1✔
195
    return element?.kind === AstNodeKind.ConditionalCompileConstStatement;
47!
196
}
197
export function isConditionalCompileErrorStatement(element: AstNode | undefined): element is ConditionalCompileErrorStatement {
1✔
198
    return element?.kind === AstNodeKind.ConditionalCompileErrorStatement;
43!
199
}
200
export function isAliasStatement(element: AstNode | undefined): element is AliasStatement {
1✔
201
    return element?.kind === AstNodeKind.AliasStatement;
83,036✔
202
}
203
export function isAugmentedAssignmentStatement(element: AstNode | undefined): element is AugmentedAssignmentStatement {
1✔
NEW
204
    return element?.kind === AstNodeKind.AugmentedAssignmentStatement;
×
205
}
206

207
// Expressions reflection
208
/**
209
 * Determine if the variablvalue is a descendent of the Expression base class.
210
 * Due to performance restrictions, this expects all statements to directly extend Expression,
211
 * so it only checks the immediate parent's class name. For example:
212
 * this will work for StringLiteralExpression -> Expression,
213
 * but will not work CustomStringLiteralExpression -> StringLiteralExpression -> Expression
214
 */
215
export function isExpression(element: AstNode | undefined): element is Expression {
1✔
216
    // eslint-disable-next-line no-bitwise
217
    return !!(element && element.visitMode & InternalWalkMode.visitExpressions);
5,718✔
218
}
219

220
export function isBinaryExpression(element: AstNode | undefined): element is BinaryExpression {
1✔
221
    return element?.kind === AstNodeKind.BinaryExpression;
25,495!
222
}
223
export function isCallExpression(element: AstNode | undefined): element is CallExpression {
1✔
224
    return element?.kind === AstNodeKind.CallExpression;
42,223!
225
}
226
export function isFunctionExpression(element: AstNode | undefined): element is FunctionExpression {
1✔
227
    return element?.kind === AstNodeKind.FunctionExpression;
16,100✔
228
}
229
export function isDottedGetExpression(element: AstNode | undefined): element is DottedGetExpression {
1✔
230
    return element?.kind === AstNodeKind.DottedGetExpression;
47,895!
231
}
232
export function isXmlAttributeGetExpression(element: AstNode | undefined): element is XmlAttributeGetExpression {
1✔
233
    return element?.kind === AstNodeKind.XmlAttributeGetExpression;
11,463!
234
}
235
export function isIndexedGetExpression(element: AstNode | undefined): element is IndexedGetExpression {
1✔
236
    return element?.kind === AstNodeKind.IndexedGetExpression;
12,163!
237
}
238
export function isGroupingExpression(element: AstNode | undefined): element is GroupingExpression {
1✔
239
    return element?.kind === AstNodeKind.GroupingExpression;
3!
240
}
241
export function isLiteralExpression(element: AstNode | undefined): element is LiteralExpression {
1✔
242
    return element?.kind === AstNodeKind.LiteralExpression;
2,383✔
243
}
244
export function isEscapedCharCodeLiteralExpression(element: AstNode | undefined): element is EscapedCharCodeLiteralExpression {
1✔
245
    return element?.kind === AstNodeKind.EscapedCharCodeLiteralExpression;
17!
246
}
247
export function isArrayLiteralExpression(element: AstNode | undefined): element is ArrayLiteralExpression {
1✔
248
    return element?.kind === AstNodeKind.ArrayLiteralExpression;
13!
249
}
250
export function isAALiteralExpression(element: AstNode | undefined): element is AALiteralExpression {
1✔
251
    return element?.kind === AstNodeKind.AALiteralExpression;
15!
252
}
253
export function isAAMemberExpression(element: AstNode | undefined): element is AAMemberExpression {
1✔
254
    return element?.kind === AstNodeKind.AAMemberExpression;
452!
255
}
256
export function isUnaryExpression(element: AstNode | undefined): element is UnaryExpression {
1✔
257
    return element?.kind === AstNodeKind.UnaryExpression;
10,317✔
258
}
259
export function isVariableExpression(element: AstNode | undefined): element is VariableExpression {
1✔
260
    return element?.kind === AstNodeKind.VariableExpression;
28,536✔
261
}
262
export function isSourceLiteralExpression(element: AstNode | undefined): element is SourceLiteralExpression {
1✔
263
    return element?.kind === AstNodeKind.SourceLiteralExpression;
2!
264
}
265
export function isNewExpression(element: AstNode | undefined): element is NewExpression {
1✔
266
    return element?.kind === AstNodeKind.NewExpression;
15,068!
267
}
268
export function isCallfuncExpression(element: AstNode | undefined): element is CallfuncExpression {
1✔
269
    return element?.kind === AstNodeKind.CallfuncExpression;
19,448!
270
}
271
export function isTemplateStringQuasiExpression(element: AstNode | undefined): element is TemplateStringQuasiExpression {
1✔
272
    return element?.kind === AstNodeKind.TemplateStringQuasiExpression;
2!
273
}
274
export function isTemplateStringExpression(element: AstNode | undefined): element is TemplateStringExpression {
1✔
275
    return element?.kind === AstNodeKind.TemplateStringExpression;
6!
276
}
277
export function isTaggedTemplateStringExpression(element: AstNode | undefined): element is TaggedTemplateStringExpression {
1✔
278
    return element?.kind === AstNodeKind.TaggedTemplateStringExpression;
2!
279
}
280
export function isFunctionParameterExpression(element: AstNode | undefined): element is FunctionParameterExpression {
1✔
281
    return element?.kind === AstNodeKind.FunctionParameterExpression;
2,202✔
282
}
283
export function isAnnotationExpression(element: AstNode | undefined): element is AnnotationExpression {
1✔
284
    return element?.kind === AstNodeKind.AnnotationExpression;
12,837!
285
}
286
export function isTypedefProvider(element: any): element is TypedefProvider {
1✔
287
    return 'getTypedef' in element;
109✔
288
}
289
export function isTypeExpression(element: any): element is TypeExpression {
1✔
290
    return element?.kind === AstNodeKind.TypeExpression;
43,510!
291
}
292
export function isTypecastExpression(element: any): element is TypecastExpression {
1✔
293
    return element?.kind === AstNodeKind.TypecastExpression;
40!
294
}
295
export function isTypedArrayExpression(element: any): element is TypedArrayExpression {
1✔
296
    return element?.kind === AstNodeKind.TypedArrayExpression;
23,545!
297
}
298

299
// BscType reflection
300
export function isStringType(value: any): value is StringType {
1✔
301
    return value?.kind === BscTypeKind.StringType;
566,825!
302
}
303
export function isTypedFunctionType(value: any): value is TypedFunctionType {
1✔
304
    return value?.kind === BscTypeKind.TypedFunctionType;
579,844✔
305
}
306
export function isFunctionType(value: any): value is FunctionType {
1✔
307
    return value?.kind === BscTypeKind.FunctionType;
573,961✔
308
}
309
export function isBooleanType(value: any): value is BooleanType {
1✔
310
    return value?.kind === BscTypeKind.BooleanType;
565,817!
311
}
312
export function isIntegerType(value: any): value is IntegerType {
1✔
313
    return value?.kind === BscTypeKind.IntegerType;
565,802!
314
}
315
export function isLongIntegerType(value: any): value is LongIntegerType {
1✔
316
    return value?.kind === BscTypeKind.LongIntegerType;
566,197!
317
}
318
export function isFloatType(value: any): value is FloatType {
1✔
319
    return value?.kind === BscTypeKind.FloatType;
566,292!
320
}
321
export function isDoubleType(value: any): value is DoubleType {
1✔
322
    return value?.kind === BscTypeKind.DoubleType;
566,192!
323
}
324
export function isInvalidType(value: any): value is InvalidType {
1✔
325
    return value?.kind === BscTypeKind.InvalidType;
566,123!
326
}
327
export function isVoidType(value: any): value is VoidType {
1✔
328
    return value?.kind === BscTypeKind.VoidType;
164!
329
}
330
export function isClassType(value: any): value is ClassType {
1✔
331
    return value?.kind === BscTypeKind.ClassType;
29,808✔
332
}
333
export function isComponentType(value: any): value is ComponentType {
1✔
334
    return value?.kind === BscTypeKind.ComponentType;
174,469✔
335
}
336
export function isDynamicType(value: any): value is DynamicType {
1✔
337
    return value?.kind === BscTypeKind.DynamicType;
198,291✔
338
}
339
export function isInterfaceType(value: any): value is InterfaceType {
1✔
340
    return value?.kind === BscTypeKind.InterfaceType;
567,737✔
341
}
342
export function isObjectType(value: any): value is ObjectType {
1✔
343
    return value?.kind === BscTypeKind.ObjectType;
1,554✔
344
}
345
export function isReferenceType(value: any): value is ReferenceType {
1✔
346
    return value?.__reflection?.name === 'ReferenceType';
570,370✔
347
}
348
export function isEnumType(value: any): value is EnumType {
1✔
349
    return value?.kind === BscTypeKind.EnumType;
4,639✔
350
}
351
export function isEnumMemberType(value: any): value is EnumMemberType {
1✔
352
    return value?.kind === BscTypeKind.EnumMemberType;
567,127!
353
}
354
export function isTypePropertyReferenceType(value: any): value is TypePropertyReferenceType {
1✔
355
    return value?.__reflection?.name === 'TypePropertyReferenceType';
7!
356
}
357
export function isBinaryOperatorReferenceType(value: any): value is BinaryOperatorReferenceType {
1✔
358
    return value?.__reflection?.name === 'BinaryOperatorReferenceType';
6!
359
}
360
export function isArrayDefaultTypeReferenceType(value: any): value is ArrayDefaultTypeReferenceType {
1✔
361
    return value?.__reflection?.name === 'ArrayDefaultTypeReferenceType';
6!
362
}
363
export function isNamespaceType(value: any): value is NamespaceType {
1✔
364
    return value?.kind === BscTypeKind.NamespaceType;
14,623✔
365
}
366
export function isUnionType(value: any): value is UnionType {
1✔
367
    return value?.kind === BscTypeKind.UnionType;
195,887✔
368
}
369
export function isUninitializedType(value: any): value is UninitializedType {
1✔
NEW
370
    return value?.kind === BscTypeKind.UninitializedType;
×
371
}
372
export function isArrayType(value: any): value is ArrayType {
1✔
373
    return value?.kind === BscTypeKind.ArrayType;
565,561!
374
}
375
export function isAssociativeArrayType(value: any): value is AssociativeArrayType {
1✔
376
    return value?.kind === BscTypeKind.AssociativeArrayType;
565,277✔
377
}
378
export function isInheritableType(target): target is InheritableType {
1✔
379
    return isClassType(target) || isInterfaceType(target) || isComponentType(target);
1,834✔
380
}
381

382
export function isCallableType(target): target is BaseFunctionType {
1✔
383
    return isFunctionType(target) || isTypedFunctionType(target);
573,957✔
384
}
385

386
export function isAnyReferenceType(target): target is AnyReferenceType {
1✔
387
    const name = target?.__reflection?.name;
2,043,405✔
388
    return name === 'ReferenceType' || name === 'TypePropertyReferenceType' || name === 'BinaryOperatorReferenceType' || name === 'ArrayDefaultTypeReferenceType';
2,043,405✔
389
}
390

391
const numberTypeKinds = [
1✔
392
    BscTypeKind.IntegerType,
393
    BscTypeKind.LongIntegerType,
394
    BscTypeKind.FloatType,
395
    BscTypeKind.DoubleType
396
];
397
export function isNumberType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType {
1✔
398
    return numberTypeKinds.includes(value?.kind);
2,095!
399
}
400

401
const primitiveTypeKinds = [
1✔
402
    ...numberTypeKinds,
403
    BscTypeKind.BooleanType,
404
    BscTypeKind.StringType
405
];
406
export function isPrimitiveType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType {
1✔
407
    return primitiveTypeKinds.includes(value?.kind);
585✔
408
}
409

410
const nativeTypeKinds = [
1✔
411
    ...primitiveTypeKinds,
412
    BscTypeKind.DynamicType,
413
    BscTypeKind.ObjectType,
414
    BscTypeKind.VoidType,
415
    BscTypeKind.FunctionType
416
];
417
export function isNativeType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType | VoidType | DynamicType | ObjectType | FunctionType {
1✔
418
    return nativeTypeKinds.includes(value?.kind);
199✔
419
}
420

421

422
// Literal reflection
423

424
export function isLiteralInvalid(value: any): value is LiteralExpression & { type: InvalidType } {
1✔
425
    return isLiteralExpression(value) && value.tokens.value.kind === TokenKind.Invalid;
6✔
426
}
427
export function isLiteralBoolean(value: any): value is LiteralExpression & { type: BooleanType } {
1✔
428
    return isLiteralExpression(value) && isBooleanType(value.getType());
36✔
429
}
430
export function isLiteralString(value: any): value is LiteralExpression & { type: StringType } {
1✔
431
    return isLiteralExpression(value) && isStringType(value.getType());
188✔
432
}
433
export function isLiteralNumber(value: any): value is LiteralExpression & { type: IntegerType | LongIntegerType | FloatType | DoubleType } {
1✔
434
    return isLiteralExpression(value) && isNumberType(value.getType());
32✔
435
}
436
export function isLiteralInteger(value: any): value is LiteralExpression & { type: IntegerType } {
1✔
437
    return isLiteralExpression(value) && isIntegerType(value.getType());
5✔
438
}
439
export function isLiteralLongInteger(value: any): value is LiteralExpression & { type: LongIntegerType } {
1✔
440
    return isLiteralExpression(value) && isLongIntegerType(value.getType());
5✔
441
}
442
export function isLiteralFloat(value: any): value is LiteralExpression & { type: FloatType } {
1✔
443
    return isLiteralExpression(value) && isFloatType(value.getType());
5✔
444
}
445
export function isLiteralDouble(value: any): value is LiteralExpression & { type: DoubleType } {
1✔
446
    return isLiteralExpression(value) && isDoubleType(value.getType());
5✔
447
}
448

449
// Diagnostics
450
export function isBsDiagnostic(value: any): value is BsDiagnostic {
1✔
451
    return value.message;
1,246✔
452
}
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