packages/walt-buildtools/src/index.js
function parseImports(ast, compiler) {
  const imports = {};
  let hasMemory = false;

  compiler.walkNode({
    Import(node, _) {
      // Import nodes consist of field and a string literal node
      const [fields, module] = node.params;
      if (imports[module.value] == null) {
        imports[module.value] = [];
      }

      compiler.walkNode({
        Pair(pair, __) {
          // Import pairs consist of identifier and type
          const [identifier, type] = pair.params;
          imports[module.value] = Array.from(
            new Set(imports[module.value].concat(identifier.value))
          );

          if (type.value === "Memory") {
            hasMemory = true;
          }
        },
      })(fields);
    },
  })(ast);

  return [imports, hasMemory];
}
function parseImports(ast, compiler) {
  const imports = {};
  let hasMemory = false;

  compiler.walkNode({
    Import(node, _) {
      // Import nodes consist of field and a string literal node
      const [fields, module] = node.params;
      if (imports[module.value] == null) {
        imports[module.value] = [];
      }

      compiler.walkNode({
        Pair(pair, __) {
          // Import pairs consist of identifier and type
          const [identifier, type] = pair.params;
          imports[module.value] = Array.from(
            new Set(imports[module.value].concat(identifier.value))
          );

          if (type.value === "Memory") {
            hasMemory = true;
          }
        },
      })(fields);
    },
  })(ast);

  return [imports, hasMemory];
}
function parseImports ( ast , compiler ) { const imports = { } ; let hasMemory = false ; compiler . walkNode ( { Import ( node , _ ) { // Import nodes consist of field and a string literal node const [ fields , module ] = node . params ; if ( imports [ module . value ] == null ) { imports [ module . value ] = [ ] ; } compiler . walkNode ( { Pair ( pair , __ ) { // Import pairs consist of identifier and type const [ identifier , type ] = pair . params ; imports [ module . value ] = Array . from ( new Set ( imports [ module . value ] . concat ( identifier . value ) ) ) ; if ( type . value === "Memory" ) { hasMemory = true ; } } , } ) ( fields ) ; } , } ) ( ast ) ; return [ imports , hasMemory ] ; }
Parse imports out of an ast
Parse imports out of an ast