@babel/plugin-bugfix-safari-class-field-initializer-scope

This bugfix plugin wraps some class field initializers with an IIFE to workaround a WebKit bug which affects Safari 15.

bugfix-safari-class-field-initializer-scope - 图1tip

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
  1. npm install --save-dev @babel/plugin-bugfix-safari-class-field-initializer-scope
  1. yarn add --dev @babel/plugin-bugfix-safari-class-field-initializer-scope
  1. pnpm add --save-dev @babel/plugin-bugfix-safari-class-field-initializer-scope

Usage

babel.config.json

  1. {
  2. "plugins": ["@babel/plugin-bugfix-safari-class-field-initializer-scope"]
  3. }

Via CLI

Shell

  1. babel --plugins @babel/plugin-bugfix-safari-class-field-initializer-scope script.js

Via Node API

JavaScript

  1. require("@babel/core").transformSync("code", {
  2. plugins: ["@babel/plugin-bugfix-safari-class-field-initializer-scope"],
  3. });