@babel/plugin-transform-reserved-words
信息
此插件包含在 @babel/preset-env
中
¥This plugin is included in @babel/preset-env
有些词在 ES3 中保留为潜在的未来关键字,但在 ES5 及更高版本中没有保留。此插件在针对 ES3 环境时使用,可重命名该组单词中的变量。
¥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
var abstract = 1;
var x = abstract + 1;
输出
¥Out
JavaScript
var _abstract = 1;
var x = _abstract + 1;
安装
¥Installation
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-transform-reserved-words
yarn add --dev @babel/plugin-transform-reserved-words
pnpm add --save-dev @babel/plugin-transform-reserved-words
用法
¥Usage
使用配置文件(推荐)
¥With a configuration file (Recommended)
babel.config.json
{
"plugins": ["@babel/plugin-transform-reserved-words"]
}
通过 CLI
¥Via CLI
Shell
babel --plugins @babel/plugin-transform-reserved-words script.js
通过 Node API
¥Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-reserved-words"],
});
参考
¥References