Update on "[compiler] Type provider infra for tests"

Adds snap/sprout support for type providers, with declarations describing some new functions in shared-runtime. This allows us to verify that the type provider infrastructure is working. I had to make a few fixes to workaround limitations in zod, but i think the types here are mostly stable enough that we won't have too much work keeping things in sync.

[ghstack-poisoned]
This commit is contained in:
Joe Savona
2024-08-21 14:20:00 -07:00
@@ -714,28 +714,23 @@ export class Environment {
}
let moduleType = this.#moduleTypes.get(moduleName);
if (moduleType === undefined) {
try {
const unparsedModuleConfig = this.config.moduleTypeProvider(moduleName);
if (unparsedModuleConfig != null) {
const parsedModuleConfig = TypeSchema.safeParse(unparsedModuleConfig);
if (!parsedModuleConfig.success) {
CompilerError.throwInvalidConfig({
reason: `Could not parse module type, the configured \`moduleTypeProvider\` function returned an invalid module description`,
description: parsedModuleConfig.error.toString(),
loc,
});
}
const moduleConfig = parsedModuleConfig.data;
moduleType = installTypeConfig(
this.#globals,
this.#shapes,
moduleConfig,
);
} else {
moduleType = null;
const unparsedModuleConfig = this.config.moduleTypeProvider(moduleName);
if (unparsedModuleConfig != null) {
const parsedModuleConfig = TypeSchema.safeParse(unparsedModuleConfig);
if (!parsedModuleConfig.success) {
CompilerError.throwInvalidConfig({
reason: `Could not parse module type, the configured \`moduleTypeProvider\` function returned an invalid module description`,
description: parsedModuleConfig.error.toString(),
loc,
});
}
} catch (e) {
console.error((e as Error).stack);
const moduleConfig = parsedModuleConfig.data;
moduleType = installTypeConfig(
this.#globals,
this.#shapes,
moduleConfig,
);
} else {
moduleType = null;
}
this.#moduleTypes.set(moduleName, moduleType);