# 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
    68686x
    68959x
    184x

    27x
    762x
    46x

    716x
    146x

    570x

    27x
    130x
    116x

    14x

    27x
    518x

    6x

    512x

    27x
    200x

    8x

    4x

    28x

    160x

    27x
    68258x
    61x
    68197x
    67x
    68130x
    344x
    67786x
    888x

    66898x

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