Skip to main content

@babel/plugin-transform-reserved-words

info

这个插件包含在 @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

在

JavaScript
var abstract = 1;
var x = abstract + 1;

出

JavaScript
var _abstract = 1;
var x = _abstract + 1;

安装​

🌐 Installation

npm install --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