# All files / src/core string.js

100% Statements 12/12
100% Branches 2/2
100% Functions 6/6
100% Lines 12/12

    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
    87x
    87x
    87x
    11x

    11x

    87x
    64x
    64x
    64x

    64x
    63x

    64x

     export default function Strings() {
      return {
        semantics: () => ({
          CharacterLiteral: _ => ([node, context], transform) => {
            const codePoint = node.value.codePointAt(0);

            return transform([
              {
                ...node,
                Type: 'Constant',
                type: 'i32',
                value: String(codePoint),
              },
              context,
            ]);
          },
          StringLiteral: _ignore => args => {
            const [stringLiteral, context] = args;
            const { statics } = context;
            const { value } = stringLiteral;

            // did we already encode the static?
            if (!(value in statics)) {
              statics[value] = null;
            }

            // It's too early to tranform a string at this point
            // we need additional information, only available in the generator.
            // This also avoids doing the work in two places, in semantics AND gen
            return stringLiteral;
          },
        }),
      };
    }