# All files / src index.js

100% Statements 30/30
88.89% Branches 8/9
100% Functions 3/3
100% Lines 30/30

    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
    69
    70
    71
    72
    73
    21x
    21x
    21x
    21x
    21x
    21x
    21x
    21x
    21x

    21x
    21x
    21x
    21x
    21x
    21x

    21x

    69x
    67x
    67x

    67x

    66x

    66x

    21x

    1x
    1x
    1x
    1x

    1x

    61x
    59x

     // @flow
    import parser from "./parser";
    import emit from "./emitter";
    import codeGenerator from "./generator";
    import semanticAnalyzer from "./semantics";
    import astValidator from "./validation";
    import _debug from "./utils/debug";
    import printNode from "./utils/print-node";
    import closurePlugin, { mapToImports } from "./closure-plugin";
    import { VERSION_1 } from "./emitter/preamble";
    import type { WebAssemblyModuleType, ConfigType } from "./flow/types";

    export const debug = _debug;
    export const prettyPrintNode = printNode;
    export const semantics = semanticAnalyzer;
    export const generator = codeGenerator;
    export const validate = astValidator;
    export const emitter = emit;
    export { parser, printNode, closurePlugin };

    // Used for deugging purposes
    export const getIR = (
      source: string,
      {
        version = VERSION_1,
        encodeNames = false,
        lines = source ? source.split("\n") : [],
        filename = "unknown",
      }: ConfigType = {}
    ) => {
      const ast = parser(source);
      const semanticAST = semantics(ast);
      validate(semanticAST, {
        lines,
        filename,
      });
      const intermediateCode = generator(semanticAST, {
        version,
        encodeNames,
        lines,
        filename,
      });
      const wasm = emitter(intermediateCode, {
        version,
        encodeNames,
        filename,
        lines,
      });
      return wasm;
    };

    export const withPlugins = (
      plugins: { [string]: WebAssemblyModuleType },
      importsObj?: { [string]: any }
    ) => {
      const { closure } = plugins;
      const resultImports = {};
      Eif (closure != null) {
        resultImports["walt-plugin-closure"] = mapToImports(closure);
      }

      return {
        ...resultImports,
        ...importsObj,
      };
    };

    // Compiles a raw binary wasm buffer
    export default function compileWalt(source: string, config: ConfigType) {
      const wasm = getIR(source, config);
      return wasm.buffer();
    }