[compiler] Ensure strict mode for EnvironmentConfigSchema
in order to throw an error for unallowed config properties
#31448
+451
−410
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Enable strict mode for
EnvironmentConfigSchema
to enforce validation and throw errors for unrecognized configuration properties. This change will help identify typos or incorrect property names in the compiler configuration, making it easier to catch and correct mistakes during setup.How did you test this change?
I verified this change within my project, confirming that errors are displayed when incorrect properties are passed to the
ReactCompilerConfig
object. Additionally, I created a test file atcompiler/packages/babel-plugin-react-compiler/src/__tests__/EnvironmentConfigSchema-test.ts
.However, I encountered issues running tests within thecompiler/packages/babel-plugin-react-compiler
package, even without my changes, despite setting up my environment correctly. While I have added the test file, I could use guidance on resolving this testing issue.Edit: the tests are now ok
Potential break
This change could disrupt some environments if the configuration contains disallowed properties, as previously these would have simply been ignored. With the new
strict()
rule, the configuration object is now restricted to only contain allowed properties. If any properties are removed in the future, developers will need to ensure they are also removed from the configuration to avoid errors. In my opinion, this approach is beneficial, as it explicitly flags incorrect properties and encourages developers to maintain a correct configuration object.As the compiler is still in beta, I think it is better to add the
strict()
now than later.