File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -62,9 +62,12 @@ const parseStringRecursively = (str: string): string => {
6262 }
6363 catch ( error ) {
6464 if ( error instanceof SyntaxError ) {
65- const charIndex = Number ( error . message . split ( ' ' ) . slice ( - 1 ) [ 0 ] )
65+ // Node.js 20: Bad escaped character in JSON at position 3
66+ // Node.js 22: Bad escaped character in JSON at position 3 (line 1 column 4)
67+ const positionMatch = error . message . match ( / a t p o s i t i o n ( \d + ) / )
68+ const charIndex = positionMatch && Number ( positionMatch [ 1 ] )
6669 // invalid escape character or number
67- if ( str [ charIndex - 1 ] === '\\' ) {
70+ if ( charIndex && str [ charIndex - 1 ] === '\\' ) {
6871 return parseStringRecursively ( str . slice ( 0 , charIndex - 1 ) + str . slice ( charIndex ) )
6972 }
7073 }
You can’t perform that action at this time.
0 commit comments