Skip to content

Commit

Permalink
fix: do not throw when creating type annotation based on bigint (#12971)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Mar 19, 2021
1 parent e2244c9 commit 8596316
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
@@ -1,4 +1,5 @@
import {
anyTypeAnnotation,
stringTypeAnnotation,
numberTypeAnnotation,
voidTypeAnnotation,
Expand All @@ -25,7 +26,8 @@ export default function createTypeAnnotationBasedOnTypeof(
| t.VoidTypeAnnotation
| t.NumberTypeAnnotation
| t.BooleanTypeAnnotation
| t.GenericTypeAnnotation {
| t.GenericTypeAnnotation
| t.AnyTypeAnnotation {
if (type === "string") {
return stringTypeAnnotation();
} else if (type === "number") {
Expand All @@ -40,7 +42,11 @@ export default function createTypeAnnotationBasedOnTypeof(
return genericTypeAnnotation(identifier("Object"));
} else if (type === "symbol") {
return genericTypeAnnotation(identifier("Symbol"));
} else if (type === "bigint") {
// todo: use BigInt annotation when Flow supports BigInt
// https://github.com/facebook/flow/issues/6639
return anyTypeAnnotation();
} else {
throw new Error("Invalid typeof value");
throw new Error("Invalid typeof value: " + type);
}
}
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`builders flow createTypeAnnotationBasedOnTypeof bigint 1`] = `
Object {
"type": "AnyTypeAnnotation",
}
`;

exports[`builders flow createTypeAnnotationBasedOnTypeof function 1`] = `
Object {
"id": Object {
Expand Down
Expand Up @@ -11,6 +11,13 @@ describe("builders", function () {
undefined: typeof undefined,
function: typeof function () {},
symbol: typeof Symbol(),
bigint: (() => {
try {
return eval("typeof 0n");
} catch (e) {
return "bigint";
}
})(),
};

for (const name in values) {
Expand Down

0 comments on commit 8596316

Please sign in to comment.