@@ -96,7 +96,7 @@ export function encode(value: unknown) {
9696 return writeUint8 ( 0xf7 ) ;
9797
9898 switch ( typeof value ) {
99- case "number" :
99+ case "number" : {
100100 if ( Math . floor ( value ) === value ) {
101101 if ( 0 <= value && value <= POW_2_53 )
102102 return writeTypeAndLength ( 0 , value ) ;
@@ -105,8 +105,9 @@ export function encode(value: unknown) {
105105 }
106106 writeUint8 ( 0xfb ) ;
107107 return writeFloat64 ( value ) ;
108+ }
108109
109- case "string" :
110+ case "string" : {
110111 const utf8data = [ ] ;
111112 for ( i = 0 ; i < value . length ; ++ i ) {
112113 let charCode = value . charCodeAt ( i ) ;
@@ -133,8 +134,9 @@ export function encode(value: unknown) {
133134
134135 writeTypeAndLength ( 3 , utf8data . length ) ;
135136 return writeUint8Array ( utf8data ) ;
137+ }
136138
137- default :
139+ default : {
138140 let length ;
139141 if ( Array . isArray ( value ) ) {
140142 length = value . length ;
@@ -154,6 +156,7 @@ export function encode(value: unknown) {
154156 encodeItem ( value [ key ] ) ;
155157 }
156158 }
159+ }
157160 }
158161 }
159162
@@ -308,11 +311,15 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
308311 throw "Invalid length" ;
309312
310313 switch ( majorType ) {
311- case 0 :
314+ case 0 : {
312315 return length ;
313- case 1 :
316+ }
317+
318+ case 1 : {
314319 return - 1 - length ;
315- case 2 :
320+ }
321+
322+ case 2 : {
316323 if ( length < 0 ) {
317324 const elements = [ ] ;
318325 let fullArrayLength = 0 ;
@@ -329,15 +336,19 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
329336 return fullArray ;
330337 }
331338 return readArrayBuffer ( length ) ;
332- case 3 :
339+ }
340+
341+ case 3 : {
333342 const utf16data = [ ] ;
334343 if ( length < 0 ) {
335344 while ( ( length = readIndefiniteStringLength ( majorType ) ) >= 0 )
336345 appendUtf16Data ( utf16data , length ) ;
337346 } else
338347 appendUtf16Data ( utf16data , length ) ;
339348 return String . fromCharCode . apply ( null , utf16data ) ;
340- case 4 :
349+ }
350+
351+ case 4 : {
341352 let retArray ;
342353 if ( length < 0 ) {
343354 retArray = [ ] ;
@@ -349,16 +360,22 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
349360 retArray [ i ] = decodeItem ( ) ;
350361 }
351362 return retArray ;
352- case 5 :
363+ }
364+
365+ case 5 : {
353366 const retObject = { } ;
354367 for ( i = 0 ; i < length || length < 0 && ! readBreak ( ) ; ++ i ) {
355368 const key = decodeItem ( ) ;
356369 retObject [ key ] = decodeItem ( ) ;
357370 }
358371 return retObject ;
359- case 6 :
372+ }
373+
374+ case 6 : {
360375 return tagger ( decodeItem ( ) , length ) ;
361- case 7 :
376+ }
377+
378+ case 7 : {
362379 switch ( length ) {
363380 case 20 :
364381 return false ;
@@ -371,6 +388,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
371388 default :
372389 return simpleValue ( length ) ;
373390 }
391+ }
374392 }
375393 }
376394
0 commit comments