# 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
    26208x
    26469x
    180x

    26x
    715x
    46x

    669x
    128x

    541x

    26x
    113x
    100x

    13x

    26x
    485x

    6x

    479x

    26x
    193x

    8x

    4x

    26x

    155x

    26x
    25814x
    60x
    25754x
    63x
    25691x
    332x
    25359x
    840x

    24519x

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