@babel/preset-stage-1
🌐 For upgrade instructions, see the README. :::
第一阶段的要点是:
🌐 The gist of Stage 1 is:
阶段 1:提案
这是什么? 对某个功能的正式提案。
需要什么? 需要确定一个所谓的“发起人”,他负责这份提案。发起人或联合发起人必须是 TC39 的成员(来源)。提案要解决的问题需要用文字描述清楚。解决方案要通过示例、API 以及语义和算法的讨论来说明。最后,还要指出提案可能遇到的障碍,比如与其他功能的交互和实现上的挑战。在实现方面,需要提供 polyfill 和演示。
接下来是什么? 当一个提案被 TC39 接受为阶段 1 时,意味着 TC39 表示愿意审查、讨论并参与贡献这个提案。未来,提案可能会有重大变化。
安装
🌐 Install
- npm
- Yarn
- pnpm
- Bun
npm install --save-dev @babel/preset-stage-1
yarn add --dev @babel/preset-stage-1
pnpm add --save-dev @babel/preset-stage-1
bun add --dev @babel/preset-stage-1
用法
🌐 Usage
使用配置文件(推荐)
🌐 With a configuration file (Recommended)
{
"presets": ["@babel/preset-stage-1"]
}
通过 CLI
🌐 Via CLI
babel script.js --presets @babel/preset-stage-1
通过 Node API
🌐 Via Node API
require("@babel/core").transformSync("code", {
presets: ["@babel/preset-stage-1"]
});
选项
🌐 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 流程》一章