fix(core): Do not user util.types.isProxy for tracking of augmented objects (#5836)

This commit is contained in:
OlegIvaniv 2023-03-30 13:29:36 +02:00 committed by GitHub
parent d86e693019
commit aacbb54bef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,15 +1,18 @@
import type { IDataObject } from './Interfaces';
import util from 'util';
const augmentedObjects = new WeakSet<object>();
function augment<T>(value: T): T {
if (
typeof value !== 'object' ||
value === null ||
util.types.isProxy(value) ||
value instanceof RegExp
value instanceof RegExp ||
augmentedObjects.has(value)
)
return value;
// Track augmented objects to prevent infinite recursion in cases where an object contains circular references
augmentedObjects.add(value);
if (value instanceof Date) return new Date(value.valueOf()) as T;
// eslint-disable-next-line @typescript-eslint/no-use-before-define