# All files / src/tokenizer/constant index.js

100% Statements 39/39
100% Branches 25/25
100% Functions 8/8
100% Lines 36/36

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    27x
    27x

    27x
    33901x
    34278x
    238x

    27x
    833x
    46x

    787x
    152x

    635x

    27x
    159x
    140x

    19x

    27x
    539x

    6x

    533x

    27x
    257x

    8x

    4x

    38x

    207x

    27x
    33515x
    70x
    33445x
    121x
    33324x
    448x
    32876x
    924x

    31952x

     // @flow
    import token from "../token";
    import Syntax from "../../Syntax";

    const { isNaN, parseInt } = Number;
    export const isNumber = (char: string) => !isNaN(parseInt(char));
    const isDot = char => char === ".";
    const number = char => (isNumber(char) ? number : null);

    const numberOrDot = char => {
      if (isDot(char)) {
        return number;
      }

      if (isNumber(char)) {
        return numberOrDot;
      }
      return null;
    };

    const hex = char => {
      if (/[0-9a-fA-F]/.test(char)) {
        return hex;
      }

      return null;
    };

    const maybeExponent = char => {
      switch (char) {
        case "e":
        case "E":
          return number;
        default:
          return numberOrDot(char);
      }
    };
    const maybeModifier = char => {
      switch (char) {
        case "b":
        case "B":
          return number;
        case "o":
          return number;
        case "x":
        case "X":
          return hex;
        default:
          return numberOrDot(char);
      }
    };

    const root = char => {
      if (char === "-") {
        return root;
      } else if (isDot(char)) {
        return number;
      } else if (char === "0") {
        return maybeModifier;
      } else if (isNumber(char)) {
        return maybeExponent;
      }

      return null;
    };

    export default token(root, Syntax.Constant);