New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix diffing object contain readonly symbol key object #10414
Changes from 9 commits
8ae2068
58af88e
95eb84c
b9fcdf6
04e47ad
930e198
b9436a1
f8e4885
8656b70
c524e02
df80075
48c5dca
b90b04f
a4208a5
6ccc83b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,8 @@ | |||||
* LICENSE file in the root directory of this source tree. | ||||||
*/ | ||||||
|
||||||
import {plugins} from 'pretty-format'; | ||||||
|
||||||
const builtInObject = [ | ||||||
Array, | ||||||
Buffer, | ||||||
|
@@ -42,6 +44,9 @@ export default function deepCyclicCopyReplaceable<T>( | |||||
return deepCyclicCopyMap(value, cycles); | ||||||
} else if (isBuiltInObject(value)) { | ||||||
return value; | ||||||
} else if (plugins.DOMElement.test(value)) { | ||||||
//@ts-expect-error skip casting to Node | ||||||
return value.cloneNode(true); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need a suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Can fix error with this, but a little bit ugly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment override is fine |
||||||
} else { | ||||||
return deepCyclicCopyObject(value, cycles); | ||||||
} | ||||||
|
@@ -55,25 +60,33 @@ function deepCyclicCopyObject<T>(object: T, cycles: WeakMap<any, any>): T { | |||||
|
||||||
cycles.set(object, newObject); | ||||||
|
||||||
Object.keys(descriptors).forEach(key => { | ||||||
if (descriptors[key].enumerable) { | ||||||
descriptors[key] = { | ||||||
const newDescriptors = [ | ||||||
...Object.keys(descriptors), | ||||||
...Object.getOwnPropertySymbols(descriptors), | ||||||
].reduce( | ||||||
//@ts-expect-error because typescript do not support symbol key in object | ||||||
//https://github.com/microsoft/TypeScript/issues/1863 | ||||||
(newDescriptors: {[x: string]: PropertyDescriptor}, key: string) => { | ||||||
const enumerable = descriptors[key].enumerable; | ||||||
|
||||||
newDescriptors[key] = { | ||||||
configurable: true, | ||||||
enumerable: true, | ||||||
enumerable, | ||||||
value: deepCyclicCopyReplaceable( | ||||||
// this accesses the value or getter, depending. We just care about the value anyways, and this allows us to not mess with accessors | ||||||
// it has the side effect of invoking the getter here though, rather than copying it over | ||||||
(object as Record<string, unknown>)[key], | ||||||
(object as Record<string | symbol, unknown>)[key], | ||||||
cycles, | ||||||
), | ||||||
writable: true, | ||||||
}; | ||||||
} else { | ||||||
delete descriptors[key]; | ||||||
} | ||||||
}); | ||||||
|
||||||
return Object.defineProperties(newObject, descriptors); | ||||||
return newDescriptors; | ||||||
}, | ||||||
{}, | ||||||
); | ||||||
//@ts-expect-error because typescript do not support symbol key in object | ||||||
//https://github.com/microsoft/TypeScript/issues/1863 | ||||||
return Object.defineProperties(newObject, newDescriptors); | ||||||
} | ||||||
|
||||||
function deepCyclicCopyArray<T>(array: Array<T>, cycles: WeakMap<any, any>): T { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe? not sure if it's better or not