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

100% Statements 26/26
100% Branches 12/12
100% Functions 6/6
100% Lines 23/23

    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
    28x
    28x

    28x
    35x

    28x
    572x
    2x

    570x
    62x

    508x

    28x
    162x
    2x

    160x
    8x

    152x

    28x
    37789x
    62x

    37727x
    8x

    37719x

    28x

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

    const quoteOK = quoteCheck => () => quoteCheck;
    const nextFails = () => null;

    const endsInSingleQuote = char => {
      if (/\\/.test(char)) {
        return quoteOK(endsInSingleQuote);
      }
      if (char === "'") {
        return nextFails;
      }

      return endsInSingleQuote;
    };

    const endsInDoubleQuote = char => {
      if (/\\/.test(char)) {
        return quoteOK(endsInDoubleQuote);
      }
      if (char === '"') {
        return nextFails;
      }

      return endsInDoubleQuote;
    };

    const maybeQuote = char => {
      if (char === "'") {
        return endsInSingleQuote;
      }
      if (char === '"') {
        return endsInDoubleQuote;
      }

      return null;
    };

    const stringParser = token(maybeQuote, Syntax.StringLiteral);
    export default stringParser;