@babel/preset-stage-2
🌐 For upgrade instructions, see the README. :::
第二阶段的要点是:
🌐 The gist of Stage 2 is:
阶段 2: 草稿
是什么? 这是规范中内容的初始版本。此时,该特性的最终纳入标准的可能性很大。
需要什么? 提案现在还必须附上该特性的语法和语义的正式描述(使用 ECMAScript 规范的形式语言)。描述应尽可能完整,但可以包含待办事项和占位符。需要有两个该特性的实验性实现,其中一个可以在像 Babel 这样的转译器中实现。
接下来做什么? 从现在开始只预期会有增量变化。
安装
🌐 Install
- npm
- Yarn
- pnpm
- Bun
npm install --save-dev @babel/preset-stage-2
yarn add --dev @babel/preset-stage-2
pnpm add --save-dev @babel/preset-stage-2
bun add --dev @babel/preset-stage-2
用法
🌐 Usage
使用配置文件(推荐)
🌐 With a configuration file (Recommended)
{
"presets": ["@babel/preset-stage-2"]
}
通过 CLI
🌐 Via CLI
babel script.js --presets @babel/preset-stage-2
通过 Node API
🌐 Via Node API
require("@babel/core").transformSync("code", {
presets: ["@babel/preset-stage-2"]
});
选项
🌐 Options
loose
boolean,默认值为 false。
为这个预设中允许的任何插件启用“宽松”转换。
🌐 Enable "loose" transformations for any plugins in this preset that allow them.
useBuiltIns
boolean,默认值为 false。
会使用原生内置功能,而不是为任何需要它的插件尝试填补行为。
🌐 Will use the native built-in instead of trying to polyfill behavior for any plugins that require one.
decoratorsLegacy
boolean,默认值为 false。
使用旧版(阶段 1)装饰器语法和行为。
🌐 Use the legacy (stage 1) decorators syntax and behavior.
你可以在这里阅读更多关于配置预设选项的信息
参考
🌐 References
- Axel Rauschmayer 在《探索 ES2016 和 ES2017》中的《ECMAScript 特性的 TC39 流程》一章