Skip to content

Commit

Permalink
fix(utils): Clone RegExp values with new RegExp instead of `struc…
Browse files Browse the repository at this point in the history
…turedClone` (fix #19245, fix #18875)

- Jest appears to provide its own global `structuredClone` that modifies
  `RegExp`s in such a way that they fail `instanceof RegExp` checks,
  causing an error in a rollup plugin used by `vite` (and likely elsewhere).
  `new RegExp` seems to correctly clone `RegExp`s in Jest.
  • Loading branch information
askoufis committed Jan 21, 2025
1 parent 9654348 commit 313966b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ function deepClone<T>(value: T): DeepWritable<T> {
return value as DeepWritable<T>
}
if (value instanceof RegExp) {
return structuredClone(value) as DeepWritable<T>
return new RegExp(value) as DeepWritable<T>
}
if (typeof value === 'object' && value != null) {
throw new Error('Cannot deep clone non-plain object')
Expand Down

0 comments on commit 313966b

Please sign in to comment.