Skip to content

Commit

Permalink
fix(VaConfig): correctly copy regex values
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ksem committed Jun 27, 2024
1 parent 9349d36 commit b9d0fcc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/ui/src/utils/clone-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ export const cloneDeep = <T>(source: T): T => {
return new Date(source.getTime()) as any
}

if (source instanceof RegExp) {
return new RegExp(source.source, source.flags) as any
}

if (source instanceof Map) {
return new Map(Array.from(source.entries()).map(([key, value]) => [key, cloneDeep(value)])) as any
}

if (source instanceof Set) {
return new Set(Array.from(source.values()).map(cloneDeep)) as any
}

if (isObject(source)) {
return Object.keys(source).reduce((acc, key) => {
acc[key] = cloneDeep(source[key as keyof T])
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/utils/merge-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const mergeDeep = (target: any, source: any): any => {
const targetValue = target[key]
const sourceValue = source[key]

if (isObject(targetValue) && isObject(sourceValue)) {
if (sourceValue instanceof RegExp || sourceValue instanceof Date) {
target[key] = sourceValue
} else if (isObject(targetValue) && isObject(sourceValue)) {
target[key] = mergeDeep(Object.create(
Object.getPrototypeOf(targetValue),
Object.getOwnPropertyDescriptors(targetValue),
Expand Down

0 comments on commit b9d0fcc

Please sign in to comment.