Skip to content

Commit

Permalink
WIP temp
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Dec 5, 2024
1 parent c018d2a commit 5df5e9b
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/analysis/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { UntypedModule } from "../parser";
import { Analysis } from "./analyse";
import { ErrorInfo } from "./errors";

export type CompilePackageOptions = {
package: string;
exposedModules: Set<string>;
packageModules: Map<string, UntypedModule>;
dependencies: Map<string, CompiledPackage>;
};

export type PackageCompilationError = {
package: string;
ns: string;
} & ErrorInfo;

export type CompiledPackage = {
package: string;
errors: Array<PackageCompilationError>;
modules: Map<string, Analysis>;
};

export function compilePackage(args: CompilePackageOptions): CompiledPackage {
const modules = new Map<string, Analysis>();
const errors: Array<PackageCompilationError> = [];

const visitPackageModule = (
ns: string,
untypedMod: UntypedModule,
): Analysis =>
new Analysis(args.package, ns, untypedMod, {
getDependency(namespace) {
// If this is a local package, visit recursively and add to tracked deps
const untypedMod = args.packageModules.get(namespace);
if (untypedMod !== undefined) {
// TODO mark this as already visited an exit if already visited
// TODO add `namespace` to tracked dependencies of `(args.package, ns)`
return visitPackageModule(ns, untypedMod);
}

for (const [, compiledPackageDep] of args.dependencies.entries()) {
// Unexposed modules aren't in this map
const d = compiledPackageDep.modules.get(namespace);
if (d !== undefined) {
return d;
}
}
return undefined;
},
});

for (const [ns, untypedMod] of args.packageModules.entries()) {
const analysis = visitPackageModule(ns, untypedMod);

modules.set(ns, analysis);
}

return {
package: args.package,
modules,
errors,
};
}

0 comments on commit 5df5e9b

Please sign in to comment.