@@ -6,11 +6,9 @@ import { createDataView, ensureUint8Array } from "./utils/typedArrays";
6
6
import { CachedKeyDecoder , KeyDecoder } from "./CachedKeyDecoder" ;
7
7
import { DecodeError } from "./DecodeError" ;
8
8
9
- const enum State {
10
- ARRAY ,
11
- MAP_KEY ,
12
- MAP_VALUE ,
13
- }
9
+ const STATE_ARRAY = "array" ;
10
+ const STATE_MAP_KEY = "map_key" ;
11
+ const STATE_MAP_VALUE = "map_value" ;
14
12
15
13
type MapKeyType = string | number ;
16
14
@@ -21,15 +19,15 @@ const isValidMapKeyType = (key: unknown): key is MapKeyType => {
21
19
} ;
22
20
23
21
type StackMapState = {
24
- type : State . MAP_KEY | State . MAP_VALUE ;
22
+ type : typeof STATE_MAP_KEY | typeof STATE_MAP_VALUE ;
25
23
size : number ;
26
24
key : MapKeyType | null ;
27
25
readCount : number ;
28
26
map : Record < string , unknown > ;
29
27
} ;
30
28
31
29
type StackArrayState = {
32
- type : State . ARRAY ;
30
+ type : typeof STATE_ARRAY ;
33
31
size : number ;
34
32
array : Array < unknown > ;
35
33
position : number ;
@@ -397,7 +395,7 @@ export class Decoder<ContextType = undefined> {
397
395
while ( stack . length > 0 ) {
398
396
// arrays and maps
399
397
const state = stack [ stack . length - 1 ] ! ;
400
- if ( state . type === State . ARRAY ) {
398
+ if ( state . type === STATE_ARRAY ) {
401
399
state . array [ state . position ] = object ;
402
400
state . position ++ ;
403
401
if ( state . position === state . size ) {
@@ -406,7 +404,7 @@ export class Decoder<ContextType = undefined> {
406
404
} else {
407
405
continue DECODE;
408
406
}
409
- } else if ( state . type === State . MAP_KEY ) {
407
+ } else if ( state . type === STATE_MAP_KEY ) {
410
408
if ( ! isValidMapKeyType ( object ) ) {
411
409
throw new DecodeError ( "The type of key must be string or number but " + typeof object ) ;
412
410
}
@@ -415,7 +413,7 @@ export class Decoder<ContextType = undefined> {
415
413
}
416
414
417
415
state . key = object ;
418
- state . type = State . MAP_VALUE ;
416
+ state . type = STATE_MAP_VALUE ;
419
417
continue DECODE;
420
418
} else {
421
419
// it must be `state.type === State.MAP_VALUE` here
@@ -428,7 +426,7 @@ export class Decoder<ContextType = undefined> {
428
426
object = state . map ;
429
427
} else {
430
428
state . key = null ;
431
- state . type = State . MAP_KEY ;
429
+ state . type = STATE_MAP_KEY ;
432
430
continue DECODE;
433
431
}
434
432
}
@@ -475,7 +473,7 @@ export class Decoder<ContextType = undefined> {
475
473
}
476
474
477
475
this . stack . push ( {
478
- type : State . MAP_KEY ,
476
+ type : STATE_MAP_KEY ,
479
477
size,
480
478
key : null ,
481
479
readCount : 0 ,
@@ -489,7 +487,7 @@ export class Decoder<ContextType = undefined> {
489
487
}
490
488
491
489
this . stack . push ( {
492
- type : State . ARRAY ,
490
+ type : STATE_ARRAY ,
493
491
size,
494
492
array : new Array < unknown > ( size ) ,
495
493
position : 0 ,
@@ -523,7 +521,7 @@ export class Decoder<ContextType = undefined> {
523
521
private stateIsMapKey ( ) : boolean {
524
522
if ( this . stack . length > 0 ) {
525
523
const state = this . stack [ this . stack . length - 1 ] ! ;
526
- return state . type === State . MAP_KEY ;
524
+ return state . type === STATE_MAP_KEY ;
527
525
}
528
526
return false ;
529
527
}
0 commit comments