@babel/plugin-transform-reserved-words

reserved-words - 图1info

This plugin is included in @babel/preset-env

Some words were reserved in ES3 as potential future keywords but were not reserved in ES5 and later. This plugin, to be used when targeting ES3 environments, renames variables from that set of words.

Example

In

JavaScript

  1. var abstract = 1;
  2. var x = abstract + 1;

Out

JavaScript

  1. var _abstract = 1;
  2. var x = _abstract + 1;

Installation

  • npm
  • Yarn
  • pnpm
  1. npm install --save-dev @babel/plugin-transform-reserved-words
  1. yarn add --dev @babel/plugin-transform-reserved-words
  1. pnpm add --save-dev @babel/plugin-transform-reserved-words

Usage

babel.config.json

  1. {
  2. "plugins": ["@babel/plugin-transform-reserved-words"]
  3. }

Via CLI

Shell

  1. babel --plugins @babel/plugin-transform-reserved-words script.js

Via Node API

JavaScript

  1. require("@babel/core").transformSync("code", {
  2. plugins: ["@babel/plugin-transform-reserved-words"],
  3. });

References