@babel/plugin-bugfix-safari-class-field-initializer-scope
此错误修复插件使用 IIFE 封装了一些类字段初始化器,以解决影响 Safari 15 的 WebKit 错误 问题。
¥This bugfix plugin wraps some class field initializers with an IIFE to workaround a WebKit bug which affects Safari 15.
提示
该插件包含在 @babel/preset-env
中,当你的 targets
受到浏览器 bug 影响时,Babel 会自动为你启用该插件。
¥This plugin is included in @babel/preset-env
, and Babel will automatically enable this plugin for you when your targets
are affected by the browser bug.
安装
¥Installation
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-bugfix-safari-class-field-initializer-scope
yarn add --dev @babel/plugin-bugfix-safari-class-field-initializer-scope
pnpm add --save-dev @babel/plugin-bugfix-safari-class-field-initializer-scope
用法
¥Usage
使用配置文件(推荐)
¥With a configuration file (Recommended)
babel.config.json
{
"plugins": ["@babel/plugin-bugfix-safari-class-field-initializer-scope"]
}
通过 CLI
¥Via CLI
Shell
babel --plugins @babel/plugin-bugfix-safari-class-field-initializer-scope script.js
通过 Node API
¥Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-bugfix-safari-class-field-initializer-scope"],
});