Repository: blitz-js/superjson (ts)

Issue:
ReferenceError: Can't find variable: BigInt
Superjson is totally broken in Safari 13. Currently affecting my client's app :grimacing:

````
ReferenceError: Can't find variable: BigInt
```

I guess we need to first check if this (and any other new types like this) are available before trying to use them.

Pull request:
Fix crash when BigInt isn't available
Closes #65 

Patch:
diff --git a/src/annotator.ts b/src/annotator.ts
index aa4173d..b1ab5ee 100644
--- a/src/annotator.ts
+++ b/src/annotator.ts
@@ -148,7 +148,6 @@ export const applyAnnotations = (plain: any, annotations: Annotations): any => {
       PathTree.expandRoot(annotations.referentialEqualities),
       (identicalObjects, path) => {
         const object = getDeep(plain, path);
-        console.log(object);
 
         PathTree.traversePaths(
           PathTree.expandRoot(identicalObjects),
diff --git a/src/transformer.ts b/src/transformer.ts
index 413c8bb..6030baf 100644
--- a/src/transformer.ts
+++ b/src/transformer.ts
@@ -72,7 +72,20 @@ const simpleRules = [
     () => null,
     () => undefined
   ),
-  simpleTransformation(isBigint, 'bigint', v => v.toString(), BigInt),
+  simpleTransformation(
+    isBigint,
+    'bigint',
+    v => v.toString(),
+    v => {
+      if (typeof BigInt !== 'undefined') {
+        return BigInt(v);
+      }
+
+      console.error('Please add a BigInt polyfill.');
+
+      return v as any;
+    }
+  ),
   simpleTransformation(
     isDate,
     'Date',


Test patch:
diff --git a/src/index.test.ts b/src/index.test.ts
index 4638741..e5fb30a 100644
--- a/src/index.test.ts
+++ b/src/index.test.ts
@@ -616,4 +616,34 @@ describe('stringify & parse', () => {
       }).toThrow();
     });
   });
+
+  test('regression #65: BigInt on Safari v13', () => {
+    const oldBigInt = global.BigInt;
+    delete global.BigInt;
+
+    const input = {
+      a: oldBigInt('1000'),
+    };
+
+    const superJSONed = SuperJSON.serialize(input);
+    expect(superJSONed).toEqual({
+      json: {
+        a: '1000',
+      },
+      meta: {
+        values: {
+          a: ['bigint'],
+        },
+      },
+    });
+
+    const deserialised = SuperJSON.deserialize(
+      JSON.parse(JSON.stringify(superJSONed))
+    );
+    expect(deserialised).toEqual({
+      a: '1000',
+    });
+
+    global.BigInt = oldBigInt;
+  });
 });