验证 门控模式 的配置。
¥Validates configuration of gating mode.
规则详情
¥Rule Details
门控模式允许你通过标记特定组件进行优化来逐步适应 React Compiler。此规则确保你的门控配置有效,以便编译器知道要处理哪些组件。
¥Gating mode lets you gradually adopt React Compiler by marking specific components for optimization. This rule ensures your gating configuration is valid so the compiler knows which components to process.
无效
¥Invalid
此规则的错误代码示例:
¥Examples of incorrect code for this rule:
// ❌ Missing required fields
module.exports = {
plugins: [
['babel-plugin-react-compiler', {
gating: {
importSpecifierName: '__experimental_useCompiler'
// Missing 'source' field
}
}]
]
};
// ❌ Invalid gating type
module.exports = {
plugins: [
['babel-plugin-react-compiler', {
gating: '__experimental_useCompiler' // Should be object
}]
]
};
有效
¥Valid
此规则的正确代码示例:
¥Examples of correct code for this rule:
// ✅ Complete gating configuration
module.exports = {
plugins: [
['babel-plugin-react-compiler', {
gating: {
importSpecifierName: 'isCompilerEnabled', // exported function name
source: 'featureFlags' // module name
}
}]
]
};
// featureFlags.js
export function isCompilerEnabled() {
// ...
}
// ✅ No gating (compile everything)
module.exports = {
plugins: [
['babel-plugin-react-compiler', {
// No gating field - compiles all components
}]
]
};