Babel 中文文档
  • 印记中文
  • 文档
  • 配置
  • 试用
  • 视频
  • 博客
  • 赞助
  • 团队
  • GitHub

›杂项

指南

  • 什么是 Babel?
  • 使用指南
  • 配置 Babel
  • 学习 ES2015
  • 升级至 Babel 7

配置参考

  • 配置文件
  • Config Options
  • 预设
  • 插件
  • 插件列表
  • Compiler assumptions

预设

  • @babel/preset-env
  • @babel/preset-react
  • @babel/preset-typescript
  • @babel/preset-flow

杂项

  • 路线图
  • 注意事项
  • 新增特性时间轴
  • FAQ
  • 编辑器

集成包

  • @babel/cli
  • @babel/polyfill
  • @babel/plugin-transform-runtime
  • @babel/register
  • @babel/standalone

工具包

  • @babel/parser
  • @babel/core
  • @babel/generator
  • @babel/code-frame
  • @babel/runtime
  • @babel/template
  • @babel/traverse
  • @babel/types

帮助工具包

  • helper-compilation-targets
  • helper-module-imports
Edit

新增特性时间轴

大多数情况下,大家都不知道在每个 Babel 版本中,我们主要引入了哪些新的特性。本文为每个小版本都做了简短摘要,你也可以在 在 GitHub 上阅读完整的更新日志! 除此之外,你也可以使用此时间轴来追踪一些其他的重要工作,例如 babel-polyfills 项目。

  1. Babel 7.19.0

    blog post

    • Support for the Stage 3 version of the decorators proposal
    • Transform support for the duplicate named capturing groups Stage 3 proposal
      /(?<year>\d\d\d\d)-(?<month>\d\d)|(?<month>\d\d)-(?<year>\d\d\d\d)/
      
  2. Babel 7.18.0

    blog post

    • TypeScript 4.7 support
    • Transform support for the Private destructuring Stage 2 proposal
      class A {
        #x = 2;
        method() {
          const { #x: x } = this;
        }
      }
      
    • No more need to manually include the regenerator-runtime helper when compiling generators
  3. Babel 7.17.0

    blog post

    • Support for the new version of the decorators Stage 2 proposal
      class A {
        @reactive #x = 2;
      
        @logger
        method() {
          this.#x++;
        }
      }
      
    • Support for the RegExp set notation and properties of strings Stage 2 proposal
      /[\p{RGI_Emoji}&&[\0-\uFFFF]]/v;
      
    • Parser support for the private destructuring Stage 2 proposal
      class A {
        #x = 2;
        method() {
          const { #x: x } = this;
        }
      }
      
  4. Babel 7.16.0

    blog post

    • Enable the class static blocks Stage 4 proposal by default
      class A {
        static {
          initialize(A);
        }
      }
      
    • TypeScript 4.5 support
    • Support ESLint 8 in @babel/eslint-parser.
  5. Babel 7.15.0

    blog post

    • Enable parsing for the top-level await Stage 4 proposal by default
      import db from "db";
      await db.connect();
      
    • Enable the Private Brand Checks Stage 4 proposal by default
      class A {
        static { initialize(A); } // static block
        #field;
        is(obj) {
          return #field in obj; // private brand check
        }
      }
      
    • Support the "Hack-style" pipeline operator Stage 2 proposal
      const result = "World" |> `Hello, ${%}!` |> alert(%);
      
    • TypeScript 4.4 support
  6. Babel 7.14.0

    blog post

    • Enable the Class Fields, Private Methods and Static Class Features Stage 4 proposals by default
    • Add the Private Brand Checks and Static Class Blocks proposals to @babel/preset-env's shippedProposals
      class A {
        static { initialize(A); } // static block
        #field;
        is(obj) {
          return #field in obj; // private brand check
        }
      }
      
    • Support for the async do expressions proposal
      let valP = async do {
        2 + await computeIt();
      };
      
    • Support for the importInterop: "node" option in @babel/plugin-transform-modules-commonjs, to aligh Babel with the Node.js behavior
    • TypeScript 4.3 support
  7. Babel 7.13.0

    博客公告

    • 升级 targets 选项 (RFC)
    • 粒度更小的编译器 assumptions (文档, RFC)
    • 支持 Records 和 Tuples 提案
      let rec = #{ x: 1 };
      let tup = #[1, 2, 3];
      
    • 支持 TypeScript 4.2
  8. Babel 7.12.0

    博客公告

    • 支持 class static blocks 提案
      class A {
        static { initialize(A); }
      }
      
    • 支持 imports and exports string names 提案
      let happy = "wooo!";
      export { happy as "😃" };
      
    • 解析器支持 Import Assertions 提案
      import json from "./foo.json" assert { type: "json" };
      
    • 支持 TypeScript 4.1
  9. Babel 7.11.0

    博客公告

    • 默认支持 Logical Assignment 和 Numeric Separator 等 4 级提案
    • 解析器支持 Decimal 提案
      console.assert(0.1m + 0.2m === 0.3m);
      
    • TypeScript 4.0 support
  10. @babel/eslint-parser

    博客公告

  11. Babel 7.10.0

    博客公告

    • 默认允许解析器支持 import.meta 等 4 级提案
    • 支持 Ergonomic brand checks for Private Fields 提案
      class Car {
        #plate;
        race(other) {
           if (#plate in other) console.log("Racing against another car!");
        }
      }
      
  12. babel-polyfills

    仓库地址

  13. Babel 7.9.0

    博客公告

    • 在 @babel/preset-env 中新增 bugfixes 选项, 以支持更灵活地解决游览器漏洞,而不是重新编译整个特性。
    • 支持 TypeScript 3.8
    • 支持 Flow declare 类字段。
    • 自动支持全新的 JSX 运行环境
  14. Babel 7.8.0

    博客公告

    • 默认支持 Optional Chaining 和 Nullish Coalescing 等 4 级提案
    • 支持 .mjs 文件类型
  15. Babel 7.7.0

    博客公告

    • 解析器支持 top-level await 提案
      import db from "./database.js";
      
      await db.connect();
      
    • 在 @babel/parser 为早期错误添加错误恢复支持。
    • 支持 .json and .cjs 文件类型
    • 支持 TypeScript 3.7
  16. Babel 7.6.0

    博客公告

    • 支持静态私有访问器,以及 static class features 提案的部分内容
      class Dog {
        static get #className() { return "Dog"; }
      }
      
  17. Babel 7.5.0

    博客公告

    • 支持 F# pipeline operator 提案
      num |> add(2) |> double
      
    • 支持 TypeScript namespace
  18. Babel 7.4.0

    博客公告

    • 支持注入 core-js@3 polyfills
    • 支持 Partial Application 提案
      strings.map(parseInt(?));
      
    • 支持静态私有方法,以及 static class features 提案的部分内容
      class Dog {
        static #register() { /* ... */ }
      }
      
    • 支持 TypeScript 3.4
  19. Babel 7.3.0

    博客公告

    • 支持实例私有访问,以及 private methods 提案的部分内容

      class Dog {
        get #randomId() { return Math.random(); }
      }
      
    • 支持 smart pipeline operator 提案

      num |> add(2, #) |> double
      
    • 在正则表达式中支持 named capturing groups

      str.match({String.raw`/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/`})
      
    • 支持 TypeScript 3.2 和 2.9

  20. Babel 7.2.0

    博客公告

    • 支持实例私有方法,以及 private methods 提案的部分内容
      class Dog {
        #bark() { console.log("Mew!") }
      }
      
  21. Babel 7.1.0

    博客公告

    • 支持 decorators 提案, 并于 2018 年 9 月指明
      class Person {
        @autoIncrement age;
      }
      
    • 支持静态私有字段,以及 static class features 提案的部分内容
      class Person {
        static #classId = 3;
      }
      
  22. Babel 7

    博客公告

    此处列出了许多变化,因为它们是两年内将要发布的内容。

    • 放弃对已不再维护的 Node 版本(0.10, 0.12, 4, 5)的支持
    • 切换到作用域包 (从 babel-core 变为 @babel/core)
    • 移除年度预设 (@babel/preset-es2015) 以及阶段预设 (@babel/preset-stage-0) (博客公告).
    • 在某些情况下添加对 "pure" (/*#__PURE__*/ )注释的支持。(后来实现为 @babel/helper-annotate-as-pure)
    • 添加项目级的 babel.config.js 配置文件 (文档) 以及 overrides 配置选项
    • 对 @babel/preset-env 补充 "useBuiltIns: "usage" 选项
    • 通过 @babel/preset-typescript 支持 TypeScript
    • 支持 JSX 语法 <></>
    • 支持一系列 TC39 提案:
      • Unicode Property Regex
      • JSON Superset
      • new.target
      • Class Private Instance Fields (class A { #b = 2 })
      • Optional Catch Binding try { throw 0 } catch { do() }
      • BigInt (syntax only)
      • import.meta (syntax only) (import.meta.url)
      • Numeric Separators (1_000)
      • function.sent
      • Optional Chaining (a?.b)
      • Logical Assignment Operators (a &&= b; a ||= b)
      • Nullish Coalescing Operator (a ?? b)
      • Pipeline Operator (a |> b)
      • Throw Expressions (() => throw new Error("a"))
← 注意事项FAQ →
  • Babel 7.19.0
  • Babel 7.18.0
  • Babel 7.17.0
  • Babel 7.16.0
  • Babel 7.15.0
  • Babel 7.14.0
  • Babel 7.13.0
  • Babel 7.12.0
  • Babel 7.11.0
  • @babel/eslint-parser
  • Babel 7.10.0
  • babel-polyfills
  • Babel 7.9.0
  • Babel 7.8.0
  • Babel 7.7.0
  • Babel 7.6.0
  • Babel 7.5.0
  • Babel 7.4.0
  • Babel 7.3.0
  • Babel 7.2.0
  • Babel 7.1.0
  • Babel 7
Babel 中文文档
文档
学习 ES2015
社区
视频用户Stack OverflowSlack 频道Twitter
更多
博客GitHub 组织GitHub 仓库Website 仓库旧版网址 6.x旧版网址 5.x