知海

规则:gating

ReactAPI 参考:ESLint 插件

gating

验证 gating 模式 的配置。

规则详情 {/rule-details/}

Gating 模式允许你通过标记特定组件来逐步采用 React Compiler。此规则确保你的 gating 配置有效,以便编译器知道要处理哪些组件。

无效用法 {/invalid/}

本规则的错误代码示例:

js 复制代码
// ❌ 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/}

本规则的正确代码示例:

js 复制代码
// ✅ 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
    }]
  ]
};

帮助我们改进文档

发现翻译问题或内容错误?请告诉我们。