packages/walt-buildtools/src/index.js
function buildTree(index, api) {
  const modules = {};

  const dependency = (module, parent) => {
    const filepath = api.resolve(module, parent);
    if (modules[filepath] != null) {
      return modules[filepath];
    }

    const src = api.getFileContents(module, parent, "utf8");
    const basic = api.parser(src);
    const [nestedImports, hasMemory] = parseImports(basic, api);

    const deps = {};

    Object.keys(nestedImports).forEach(mod => {
      if (mod.indexOf(".") === 0) {
        const dep = dependency(mod, filepath);
        deps[mod] = dep;
      }
    });

    const patched = inferImportTypes(basic, deps, api);
    const ast = api.semantics(patched);

    api.validate(ast, {
      lines: src.split("\n"),
      filename: module.split("/").pop(),
    });

    const result = {
      ast,
      deps,
      filepath,
      hasMemory,
    };
    modules[filepath] = result;

    return result;
  };

  const root = dependency(index, null);

  return {
    root,
    modules,
  };
}
function buildTree(index, api) {
  const modules = {};

  const dependency = (module, parent) => {
    const filepath = api.resolve(module, parent);
    if (modules[filepath] != null) {
      return modules[filepath];
    }

    const src = api.getFileContents(module, parent, "utf8");
    const basic = api.parser(src);
    const [nestedImports, hasMemory] = parseImports(basic, api);

    const deps = {};

    Object.keys(nestedImports).forEach(mod => {
      if (mod.indexOf(".") === 0) {
        const dep = dependency(mod, filepath);
        deps[mod] = dep;
      }
    });

    const patched = inferImportTypes(basic, deps, api);
    const ast = api.semantics(patched);

    api.validate(ast, {
      lines: src.split("\n"),
      filename: module.split("/").pop(),
    });

    const result = {
      ast,
      deps,
      filepath,
      hasMemory,
    };
    modules[filepath] = result;

    return result;
  };

  const root = dependency(index, null);

  return {
    root,
    modules,
  };
}
function buildTree ( index , api ) { const modules = { } ; const dependency = ( module , parent ) => { const filepath = api . resolve ( module , parent ) ; if ( modules [ filepath ] != null ) { return modules [ filepath ] ; } const src = api . getFileContents ( module , parent , "utf8" ) ; const basic = api . parser ( src ) ; const [ nestedImports , hasMemory ] = parseImports ( basic , api ) ; const deps = { } ; Object . keys ( nestedImports ) . forEach ( mod => { if ( mod . indexOf ( "." ) === 0 ) { const dep = dependency ( mod , filepath ) ; deps [ mod ] = dep ; } } ) ; const patched = inferImportTypes ( basic , deps , api ) ; const ast = api . semantics ( patched ) ; api . validate ( ast , { lines : src . split ( "\n" ) , filename : module . split ( "/" ) . pop ( ) , } ) ; const result = { ast , deps , filepath , hasMemory , } ; modules [ filepath ] = result ; return result ; } ; const root = dependency ( index , null ) ; return { root , modules , } ; }
Build a dependency tree of ASTs given a root module
Build a dependency tree of ASTs given a root module