File tree Expand file tree Collapse file tree 2 files changed +10
-13
lines changed Expand file tree Collapse file tree 2 files changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -16,14 +16,11 @@ export function parse(serialized) {
16
16
17
17
if ( typeof parsed === 'number' ) return hydrate ( parsed , true ) ;
18
18
19
- if ( ! Array . isArray ( parsed ) ) {
20
- throw new SyntaxError (
21
- `Expected array, got ${ parsed === null ? 'null' : typeof parsed } `
22
- ) ;
19
+ if ( ! Array . isArray ( parsed ) || parsed . length === 0 ) {
20
+ throw new SyntaxError ( 'Invalid input' ) ;
23
21
}
24
22
25
23
const values = /** @type {any[] } */ ( parsed ) ;
26
- if ( values . length === 0 ) throw new SyntaxError ( `Unexpected empty array` ) ;
27
24
28
25
const hydrated = Array ( values . length ) ;
29
26
@@ -35,7 +32,7 @@ export function parse(serialized) {
35
32
if ( index === NEGATIVE_INFINITY ) return - Infinity ;
36
33
if ( index === NEGATIVE_ZERO ) return - 0 ;
37
34
38
- if ( standalone ) throw new SyntaxError ( `Unexpected number ${ index } ` ) ;
35
+ if ( standalone ) throw new SyntaxError ( `Invalid input ` ) ;
39
36
40
37
if ( index in hydrated ) return hydrated [ index ] ;
41
38
Original file line number Diff line number Diff line change @@ -404,37 +404,37 @@ const invalid = [
404
404
{
405
405
name : 'hole' ,
406
406
json : '-2' ,
407
- message : 'Unexpected number -2 '
407
+ message : 'Invalid input '
408
408
} ,
409
409
{
410
410
name : 'string' ,
411
411
json : '"hello"' ,
412
- message : 'Expected array, got string '
412
+ message : 'Invalid input '
413
413
} ,
414
414
{
415
415
name : 'number' ,
416
416
json : '42' ,
417
- message : 'Unexpected number 42 '
417
+ message : 'Invalid input '
418
418
} ,
419
419
{
420
420
name : 'boolean' ,
421
421
json : 'true' ,
422
- message : 'Expected array, got boolean '
422
+ message : 'Invalid input '
423
423
} ,
424
424
{
425
425
name : 'null' ,
426
426
json : 'null' ,
427
- message : 'Expected array, got null '
427
+ message : 'Invalid input '
428
428
} ,
429
429
{
430
430
name : 'object' ,
431
431
json : '{}' ,
432
- message : 'Expected array, got object '
432
+ message : 'Invalid input '
433
433
} ,
434
434
{
435
435
name : 'empty array' ,
436
436
json : '[]' ,
437
- message : 'Unexpected empty array '
437
+ message : 'Invalid input '
438
438
}
439
439
] ;
440
440
You can’t perform that action at this time.
0 commit comments