( object: any, identities: Map<any, any[][]>, superJson: SuperJSON, dedupe: boolean, path: any[] = [], objectsInThisPath: any[] = [], seenObjects = new Map<unknown, Result>() )
| 186 | } |
| 187 | |
| 188 | export const walker = ( |
| 189 | object: any, |
| 190 | identities: Map<any, any[][]>, |
| 191 | superJson: SuperJSON, |
| 192 | dedupe: boolean, |
| 193 | path: any[] = [], |
| 194 | objectsInThisPath: any[] = [], |
| 195 | seenObjects = new Map<unknown, Result>() |
| 196 | ): Result => { |
| 197 | const primitive = isPrimitive(object); |
| 198 | |
| 199 | if (!primitive) { |
| 200 | addIdentity(object, path, identities); |
| 201 | |
| 202 | const seen = seenObjects.get(object); |
| 203 | if (seen) { |
| 204 | // short-circuit result if we've seen this object before |
| 205 | return dedupe |
| 206 | ? { |
| 207 | transformedValue: null, |
| 208 | } |
| 209 | : seen; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | if (!isDeep(object, superJson)) { |
| 214 | const transformed = transformValue(object, superJson); |
| 215 | |
| 216 | const result: Result = transformed |
| 217 | ? { |
| 218 | transformedValue: transformed.value, |
| 219 | annotations: [transformed.type], |
| 220 | } |
| 221 | : { |
| 222 | transformedValue: object, |
| 223 | }; |
| 224 | if (!primitive) { |
| 225 | seenObjects.set(object, result); |
| 226 | } |
| 227 | return result; |
| 228 | } |
| 229 | |
| 230 | if (includes(objectsInThisPath, object)) { |
| 231 | // prevent circular references |
| 232 | return { |
| 233 | transformedValue: null, |
| 234 | }; |
| 235 | } |
| 236 | |
| 237 | const transformationResult = transformValue(object, superJson); |
| 238 | const transformed = transformationResult?.value ?? object; |
| 239 | |
| 240 | const transformedValue: any = isArray(transformed) ? [] : {}; |
| 241 | const innerAnnotations: Record<string, Tree<TypeAnnotation>> = {}; |
| 242 | |
| 243 | forEach(transformed, (value, index) => { |
| 244 | if ( |
| 245 | index === '__proto__' || |
no test coverage detected
searching dependent graphs…