@babel/plugin-transform-reserved-words
資訊
此外掛程式包含在 @babel/preset-env
中
某些字詞在 ES3 中保留為潛在的未來關鍵字,但在 ES5 及之後的版本中未保留。此外掛程式用於鎖定 ES3 環境時,會將變數從該組字詞中重新命名。
範例
在
JavaScript
var abstract = 1;
var x = abstract + 1;
輸出
JavaScript
var _abstract = 1;
var x = _abstract + 1;
安裝
- 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
用法
使用設定檔 (建議)
babel.config.json
{
"plugins": ["@babel/plugin-transform-reserved-words"]
}
透過 CLI
Shell
babel --plugins @babel/plugin-transform-reserved-words script.js
透過 Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-reserved-words"],
});