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 {
|
import {
|
||||||
|
anyTypeAnnotation,
|
||||||
stringTypeAnnotation,
|
stringTypeAnnotation,
|
||||||
numberTypeAnnotation,
|
numberTypeAnnotation,
|
||||||
voidTypeAnnotation,
|
voidTypeAnnotation,
|
||||||
@ -25,7 +26,8 @@ export default function createTypeAnnotationBasedOnTypeof(
|
|||||||
| t.VoidTypeAnnotation
|
| t.VoidTypeAnnotation
|
||||||
| t.NumberTypeAnnotation
|
| t.NumberTypeAnnotation
|
||||||
| t.BooleanTypeAnnotation
|
| t.BooleanTypeAnnotation
|
||||||
| t.GenericTypeAnnotation {
|
| t.GenericTypeAnnotation
|
||||||
|
| t.AnyTypeAnnotation {
|
||||||
if (type === "string") {
|
if (type === "string") {
|
||||||
return stringTypeAnnotation();
|
return stringTypeAnnotation();
|
||||||
} else if (type === "number") {
|
} else if (type === "number") {
|
||||||
@ -40,7 +42,11 @@ export default function createTypeAnnotationBasedOnTypeof(
|
|||||||
return genericTypeAnnotation(identifier("Object"));
|
return genericTypeAnnotation(identifier("Object"));
|
||||||
} else if (type === "symbol") {
|
} else if (type === "symbol") {
|
||||||
return genericTypeAnnotation(identifier("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 {
|
} 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
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`builders flow createTypeAnnotationBasedOnTypeof bigint 1`] = `
|
||||||
|
Object {
|
||||||
|
"type": "AnyTypeAnnotation",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`builders flow createTypeAnnotationBasedOnTypeof function 1`] = `
|
exports[`builders flow createTypeAnnotationBasedOnTypeof function 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"id": Object {
|
"id": Object {
|
||||||
|
|||||||
@ -11,6 +11,13 @@ describe("builders", function () {
|
|||||||
undefined: typeof undefined,
|
undefined: typeof undefined,
|
||||||
function: typeof function () {},
|
function: typeof function () {},
|
||||||
symbol: typeof Symbol(),
|
symbol: typeof Symbol(),
|
||||||
|
bigint: (() => {
|
||||||
|
try {
|
||||||
|
return eval("typeof 0n");
|
||||||
|
} catch (e) {
|
||||||
|
return "bigint";
|
||||||
|
}
|
||||||
|
})(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const name in values) {
|
for (const name in values) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user