@tsed/core 6.75.8 → 6.75.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +18 -3
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +18 -3
- package/lib/index.modern.js.map +1 -1
- package/lib/utils/objects/deepClone.d.ts +2 -1
- package/package.json +1 -1
package/lib/index.modern.js
CHANGED
|
@@ -385,10 +385,11 @@ const isBasicType = source => isNil(source) || isPrimitive(source) || isSymbol(s
|
|
|
385
385
|
/**
|
|
386
386
|
* Return a cloned value
|
|
387
387
|
* @param source
|
|
388
|
+
* @param stack
|
|
388
389
|
*/
|
|
389
390
|
|
|
390
391
|
|
|
391
|
-
function deepClone(source) {
|
|
392
|
+
function deepClone(source, stack = new WeakMap()) {
|
|
392
393
|
let dest;
|
|
393
394
|
|
|
394
395
|
if (isBasicType(source)) {
|
|
@@ -399,7 +400,21 @@ function deepClone(source) {
|
|
|
399
400
|
return new Date(source);
|
|
400
401
|
}
|
|
401
402
|
|
|
402
|
-
|
|
403
|
+
const stacked = stack.get(source);
|
|
404
|
+
|
|
405
|
+
if (stacked) {
|
|
406
|
+
// See issue #1619
|
|
407
|
+
// istanbul ignore next
|
|
408
|
+
process.env.TSED_TRACK_CIRCULAR_REF && console.trace("Circular ref detected on deepClone", stacked);
|
|
409
|
+
return stacked;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (isArray(source)) {
|
|
413
|
+
dest = [];
|
|
414
|
+
} else {
|
|
415
|
+
dest = {};
|
|
416
|
+
stack.set(source, dest);
|
|
417
|
+
}
|
|
403
418
|
|
|
404
419
|
for (const key in source) {
|
|
405
420
|
// Use getOwnPropertyDescriptor instead of source[key] to prevent from triggering setter/getter.
|
|
@@ -407,7 +422,7 @@ function deepClone(source) {
|
|
|
407
422
|
|
|
408
423
|
if (descriptor) {
|
|
409
424
|
if (!isFunction(descriptor.value)) {
|
|
410
|
-
dest[key] = deepClone(descriptor.value);
|
|
425
|
+
dest[key] = deepClone(descriptor.value, stack);
|
|
411
426
|
} else {
|
|
412
427
|
Object.defineProperty(dest, key, descriptor);
|
|
413
428
|
}
|