@@ -6,11 +6,9 @@ import { createDataView, ensureUint8Array } from "./utils/typedArrays";
66import { CachedKeyDecoder , KeyDecoder } from "./CachedKeyDecoder" ;
77import { DecodeError } from "./DecodeError" ;
88
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" ;
1412
1513type MapKeyType = string | number ;
1614
@@ -21,15 +19,15 @@ const isValidMapKeyType = (key: unknown): key is MapKeyType => {
2119} ;
2220
2321type StackMapState = {
24- type : State . MAP_KEY | State . MAP_VALUE ;
22+ type : typeof STATE_MAP_KEY | typeof STATE_MAP_VALUE ;
2523 size : number ;
2624 key : MapKeyType | null ;
2725 readCount : number ;
2826 map : Record < string , unknown > ;
2927} ;
3028
3129type StackArrayState = {
32- type : State . ARRAY ;
30+ type : typeof STATE_ARRAY ;
3331 size : number ;
3432 array : Array < unknown > ;
3533 position : number ;
@@ -397,7 +395,7 @@ export class Decoder<ContextType = undefined> {
397395 while ( stack . length > 0 ) {
398396 // arrays and maps
399397 const state = stack [ stack . length - 1 ] ! ;
400- if ( state . type === State . ARRAY ) {
398+ if ( state . type === STATE_ARRAY ) {
401399 state . array [ state . position ] = object ;
402400 state . position ++ ;
403401 if ( state . position === state . size ) {
@@ -406,7 +404,7 @@ export class Decoder<ContextType = undefined> {
406404 } else {
407405 continue DECODE;
408406 }
409- } else if ( state . type === State . MAP_KEY ) {
407+ } else if ( state . type === STATE_MAP_KEY ) {
410408 if ( ! isValidMapKeyType ( object ) ) {
411409 throw new DecodeError ( "The type of key must be string or number but " + typeof object ) ;
412410 }
@@ -415,7 +413,7 @@ export class Decoder<ContextType = undefined> {
415413 }
416414
417415 state . key = object ;
418- state . type = State . MAP_VALUE ;
416+ state . type = STATE_MAP_VALUE ;
419417 continue DECODE;
420418 } else {
421419 // it must be `state.type === State.MAP_VALUE` here
@@ -428,7 +426,7 @@ export class Decoder<ContextType = undefined> {
428426 object = state . map ;
429427 } else {
430428 state . key = null ;
431- state . type = State . MAP_KEY ;
429+ state . type = STATE_MAP_KEY ;
432430 continue DECODE;
433431 }
434432 }
@@ -475,7 +473,7 @@ export class Decoder<ContextType = undefined> {
475473 }
476474
477475 this . stack . push ( {
478- type : State . MAP_KEY ,
476+ type : STATE_MAP_KEY ,
479477 size,
480478 key : null ,
481479 readCount : 0 ,
@@ -489,7 +487,7 @@ export class Decoder<ContextType = undefined> {
489487 }
490488
491489 this . stack . push ( {
492- type : State . ARRAY ,
490+ type : STATE_ARRAY ,
493491 size,
494492 array : new Array < unknown > ( size ) ,
495493 position : 0 ,
@@ -523,7 +521,7 @@ export class Decoder<ContextType = undefined> {
523521 private stateIsMapKey ( ) : boolean {
524522 if ( this . stack . length > 0 ) {
525523 const state = this . stack [ this . stack . length - 1 ] ! ;
526- return state . type === State . MAP_KEY ;
524+ return state . type === STATE_MAP_KEY ;
527525 }
528526 return false ;
529527 }
0 commit comments