# 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
    26x
    26x

    26x
    24313x
    24574x
    179x

    26x
    684x
    46x

    638x
    112x

    526x

    26x
    123x
    108x

    15x

    26x
    464x

    6x

    458x

    26x
    195x

    8x

    4x

    30x

    153x

    26x
    23948x
    58x
    23890x
    62x
    23828x
    332x
    23496x
    814x

    22682x

     // @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);