@samitouri / QOS-React-1 / commits / a1e3891189

[rfc][babel] InvalidConfig always throws

When you have your panic threshold set to "NONE" as we recommend, it's easy to miss that your config is wrong (which makes everything not compile) because those errors were being silenced. This made debugging FluentUI and the forget-feedback testapp pretty difficult to figure out at first, and defeats the purpose of having config validation in the first place. This pr makes it so InvalidConfig errors always throw, regardless of the panic threshold set. In general our plugin should never throw at build time due to component bailouts, but because an InvalidConfig would bailout everything from being compiled at all, it seems reasonable to throw here

Lauren Tan committed Nov 17, 2023 at 12:01 UTC a1e389118951ff7b83c753245ee96793a898bfe0
1 file changed +11 -7
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+11 -7
@@ -59,6 +59,15 @@ function isCriticalError(err: unknown): boolean {
59 return !(err instanceof CompilerError) || err.isCritical();
60 }
61
62 +function isConfigError(err: unknown): boolean {
63 + if (err instanceof CompilerError) {
64 + return err.details.some(
65 + (detail) => detail.severity === ErrorSeverity.InvalidConfig
66 + );
67 + }
68 + return false;
69 +}
70 +
71 type BabelFn =
72 | NodePath<t.FunctionDeclaration>
73 | NodePath<t.FunctionExpression>
@@ -98,15 +107,10 @@ function handleError(
107 });
108 }
109 }
101 - /*
102 - * Always throw if the flag is enabled, otherwise we only throw if the error is critical
103 - * (eg an invariant is broken, meaning the compiler may be buggy). See
104 - * {@link CompilerError.isCritical} for mappings.
105 - *
106 - */
110 if (
111 pass.opts.panicThreshold === "ALL_ERRORS" ||
109 - (pass.opts.panicThreshold === "CRITICAL_ERRORS" && isCriticalError(err))
112 + (pass.opts.panicThreshold === "CRITICAL_ERRORS" && isCriticalError(err)) ||
113 + isConfigError(err) // Always throws regardless of panic threshold
114 ) {
115 throw err;
116 }