mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user