# All files / src/generator initializer.js

100% Statements 12/12
100% Branches 7/7
100% Functions 1/1
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
    23x
    23x

    23x
    20x
    20x
    20x
    19x
    19x

    2x
    2x

    17x

    20x

     // @flow
    import { generateValueType } from "./utils";
    import { I32, I64, F32, F64 } from "../emitter/value_type";
    import type { NodeType, IntermediateVariableType } from "./flow/types";

    const generateInit = (node: NodeType): IntermediateVariableType => {
      const _global = generateValueType(node);
      const [initializer] = node.params;
      if (initializer != null) {
        const { value } = initializer;
        switch (_global.type) {
          case F32:
          case F64:
            _global.init = parseFloat(value);
            break;
          case I32:
          case I64:
          default:
            _global.init = parseInt(value);
        }
      }

      return _global;
    };

    export default generateInit;