aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@babel/core/src/transformation/util/clone-deep-browser.ts
blob: 78ae53ebf0874db9d7a003698d2a24d0e0a322e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const serialized = "$$ babel internal serialized type" + Math.random();

function serialize(key, value) {
  if (typeof value !== "bigint") return value;
  return {
    [serialized]: "BigInt",
    value: value.toString(),
  };
}

function revive(key, value) {
  if (!value || typeof value !== "object") return value;
  if (value[serialized] !== "BigInt") return value;
  return BigInt(value.value);
}

export default function (value) {
  return JSON.parse(JSON.stringify(value, serialize), revive);
}