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

    26x
    95x

    26x
    718x
    2x

    716x
    70x

    646x

    26x
    2534x
    2x

    2532x
    120x

    2412x

    26x
    52658x
    70x

    52588x
    120x

    52468x

    26x

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