fix: do not throw when creating type annotation based on bigint (#12971)
This commit is contained in:
parent
e2244c92d9
commit
85963167b4
@ -1,4 +1,5 @@
|
||||
import {
|
||||
anyTypeAnnotation,
|
||||
stringTypeAnnotation,
|
||||
numberTypeAnnotation,
|
||||
voidTypeAnnotation,
|
||||
@ -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") {
|
||||
@ -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 {
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user