@@ -15,19 +15,23 @@ const evaluate = (
1515 const { result, computed : referenceTokens } = parse ( jsonPointer , parseOptions ) ;
1616
1717 if ( ! result . success ) {
18- throw new JSONPointerEvaluateError ( `Invalid JSON Pointer: ${ jsonPointer } ` ) ;
18+ throw new JSONPointerEvaluateError ( `Invalid JSON Pointer: ${ jsonPointer } ` , {
19+ jsonPointer,
20+ } ) ;
1921 }
2022
21- return referenceTokens . reduce ( ( current , referenceToken ) => {
22- if ( typeof current !== 'object' || current === null ) {
23- throw new JSONPointerTypeError ( referenceToken ) ;
24- }
25-
23+ return referenceTokens . reduce ( ( current , referenceToken , referenceTokenPosition ) => {
2624 if ( Array . isArray ( current ) ) {
2725 if ( testArrayDash ( referenceToken ) ) {
2826 if ( strictArrays ) {
2927 throw new JSONPointerIndexError (
3028 'Invalid array index: "-" always refers to a nonexistent element during evaluation' ,
29+ {
30+ jsonPointer,
31+ referenceTokens,
32+ referenceToken,
33+ referenceTokenPosition,
34+ } ,
3135 ) ;
3236 } else {
3337 return current [ current . length ] ;
@@ -37,21 +41,47 @@ const evaluate = (
3741 if ( ! testArrayIndex ( referenceToken ) && strictArrays ) {
3842 throw new JSONPointerIndexError (
3943 `Invalid array index: '${ referenceToken } ' (MUST be "0", or digits without a leading "0")` ,
44+ {
45+ jsonPointer,
46+ referenceTokens,
47+ referenceToken,
48+ referenceTokenPosition,
49+ } ,
4050 ) ;
4151 }
4252
4353 const index = Number ( referenceToken ) ;
4454 if ( index >= current . length && strictArrays ) {
45- throw new JSONPointerIndexError ( `Invalid array index: '${ index } ' out of bounds` ) ;
55+ throw new JSONPointerIndexError ( `Invalid array index: '${ index } ' out of bounds` , {
56+ jsonPointer,
57+ referenceTokens,
58+ referenceToken : index ,
59+ referenceTokenPosition,
60+ } ) ;
4661 }
4762 return current [ index ] ;
4863 }
4964
50- if ( ! Object . prototype . hasOwnProperty . call ( current , referenceToken ) && strictObjects ) {
51- throw new JSONPointerKeyError ( referenceToken ) ;
65+ if ( typeof current === 'object' && current !== null ) {
66+ if ( ! Object . prototype . hasOwnProperty . call ( current , referenceToken ) && strictObjects ) {
67+ throw new JSONPointerKeyError ( undefined , {
68+ jsonPointer,
69+ referenceTokens,
70+ referenceToken,
71+ referenceTokenPosition,
72+ } ) ;
73+ }
74+
75+ return current [ referenceToken ] ;
5276 }
5377
54- return current [ referenceToken ] ;
78+ throw new JSONPointerTypeError ( undefined , {
79+ jsonPointer,
80+ referenceTokens,
81+ referenceToken,
82+ referenceTokenPosition,
83+ currentValue : current ,
84+ } ) ;
5585 } , value ) ;
5686} ;
5787
0 commit comments