Skip to content

Commit

Permalink
fix(cloneDeep): cloneDeep should clone own enumerable symbol property (
Browse files Browse the repository at this point in the history
…#664)

* fix(cloneDeep): cloneDeep should clone own enumerable symbol property

* Update src/object/cloneDeep.ts

* Update cloneDeep.ts

---------

Co-authored-by: Sojin Park <[email protected]>
  • Loading branch information
mass2527 and raon0211 authored Oct 14, 2024
1 parent 61f5f88 commit 49ff1b4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/object/cloneDeep.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('cloneDeep', () => {
// object
//-------------------------------------------------------------------------------------
it('should clone objects', () => {
const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3], [Symbol()]: 2 };
const clonedObj = cloneDeep(obj);

expect(clonedObj).toEqual(obj);
Expand Down
3 changes: 2 additions & 1 deletion src/object/cloneDeep.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getSymbols } from '../compat/_internal/getSymbols.ts';
import { isPrimitive } from '../predicate/isPrimitive.ts';
import { isTypedArray } from '../predicate/isTypedArray.ts';

Expand Down Expand Up @@ -196,7 +197,7 @@ function cloneDeepImpl<T>(obj: T, stack = new Map<any, any>()): T {

// eslint-disable-next-line
export function copyProperties(target: any, source: any, stack?: Map<any, any>): void {
const keys = Object.keys(source);
const keys = [...Object.keys(source), ...getSymbols(source)];

for (let i = 0; i < keys.length; i++) {
const key = keys[i];
Expand Down

0 comments on commit 49ff1b4

Please sign in to comment.