Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not throw when creating type annotation based on bigint #12971

Merged
merged 4 commits into from Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not use numberTypeAnnotation here because Math functions do not work with BigInt. Mark it as any as it is not supported in Flow.

} 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