babel / babel

@@ -9,44 +9,40 @@
Loading
9 9
} from "../generated";
10 10
import type * as t from "../..";
11 11
12 +
export default createTypeAnnotationBasedOnTypeof as {
13 +
  (type: "string"): t.StringTypeAnnotation;
14 +
  (type: "number"): t.NumberTypeAnnotation;
15 +
  (type: "undefined"): t.VoidTypeAnnotation;
16 +
  (type: "boolean"): t.BooleanTypeAnnotation;
17 +
  (type: "function"): t.GenericTypeAnnotation;
18 +
  (type: "object"): t.GenericTypeAnnotation;
19 +
  (type: "symbol"): t.GenericTypeAnnotation;
20 +
  (type: "bigint"): t.AnyTypeAnnotation;
21 +
};
22 +
12 23
/**
13 24
 * Create a type annotation based on typeof expression.
14 25
 */
15 -
export default function createTypeAnnotationBasedOnTypeof(
16 -
  type:
17 -
    | "string"
18 -
    | "number"
19 -
    | "undefined"
20 -
    | "boolean"
21 -
    | "function"
22 -
    | "object"
23 -
    | "symbol",
24 -
):
25 -
  | t.StringTypeAnnotation
26 -
  | t.VoidTypeAnnotation
27 -
  | t.NumberTypeAnnotation
28 -
  | t.BooleanTypeAnnotation
29 -
  | t.GenericTypeAnnotation
30 -
  | t.AnyTypeAnnotation {
31 -
  if (type === "string") {
32 -
    return stringTypeAnnotation();
33 -
  } else if (type === "number") {
34 -
    return numberTypeAnnotation();
35 -
  } else if (type === "undefined") {
36 -
    return voidTypeAnnotation();
37 -
  } else if (type === "boolean") {
38 -
    return booleanTypeAnnotation();
39 -
  } else if (type === "function") {
40 -
    return genericTypeAnnotation(identifier("Function"));
41 -
  } else if (type === "object") {
42 -
    return genericTypeAnnotation(identifier("Object"));
43 -
  } else if (type === "symbol") {
44 -
    return genericTypeAnnotation(identifier("Symbol"));
45 -
  } else if (type === "bigint") {
46 -
    // todo: use BigInt annotation when Flow supports BigInt
47 -
    // https://github.com/facebook/flow/issues/6639
48 -
    return anyTypeAnnotation();
49 -
  } else {
50 -
    throw new Error("Invalid typeof value: " + type);
26 +
function createTypeAnnotationBasedOnTypeof(type: string): t.FlowType {
27 +
  switch (type) {
28 +
    case "string":
29 +
      return stringTypeAnnotation();
30 +
    case "number":
31 +
      return numberTypeAnnotation();
32 +
    case "undefined":
33 +
      return voidTypeAnnotation();
34 +
    case "boolean":
35 +
      return booleanTypeAnnotation();
36 +
    case "function":
37 +
      return genericTypeAnnotation(identifier("Function"));
38 +
    case "object":
39 +
      return genericTypeAnnotation(identifier("Object"));
40 +
    case "symbol":
41 +
      return genericTypeAnnotation(identifier("Symbol"));
42 +
    case "bigint":
43 +
      // todo: use BigInt annotation when Flow supports BigInt
44 +
      // https://github.com/facebook/flow/issues/6639
45 +
      return anyTypeAnnotation();
51 46
  }
47 +
  throw new Error("Invalid typeof value: " + type);
52 48
}
Files Coverage
codemods 100.00%
eslint 95.07%
packages 91.90%
Project Totals (458 files) 92.01%
1
coverage:
2
  parsers:
3
    javascript:
4
      enable_partials: yes
5
  status:
6
    project:
7
      default:
8
        target: "90%"
9
    patch:
10
      enabled: false
11
ignore:
12
  - packages/babel-types/src/*/generated/*
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading