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

›All Blog Posts

All Blog Posts

  • 7.19.0 Released: Stage 3 decorators and more RegExp features!
  • 7.18.0 Released: Destructuring private elements and TypeScript 4.7
  • 7.17.0 Released: RegExp 'v' mode and ... 🥁 decorators!
  • 7.16.0 发布: ESLint 8 和 TypeScript 4.5
  • 7.15.0 发布:支持 Hack-style 管道, TypeScript 枚举常量和 Rhino 目标
  • Babel is used by millions, so why are we running out of money?
  • 7.14.0 Released: New class features enabled by default, TypeScript 4.3, and better CommonJS interop
  • 7.13.0 Released: Records and Tuples, granular compiler assumptions, and top-level targets
  • 7.12.0 Released: TypeScript 4.1, strings as import/export names, and class static blocks
  • 7.11.0 Released: ECMAScript 2021 support in preset-env, TypeScript 4.0 support, printing config and the future of `babel-eslint`
  • The State of babel-eslint
  • 7.10.0 Released: Class Fields in preset-env, '#private in' checks and better React tree-shaking
  • 7.9.0 Released: Smaller preset-env output, Typescript 3.8 support and a new JSX transform
  • 7.8.0 Released: ECMAScript 2020, .mjs configuration files and @babel/cli improvements
  • Babel's Funding Plans
  • 7.7.0 Released: Error recovery and TypeScript 3.7
  • 7.6.0 Released: Private static accessors and V8 intrinsic syntax
  • 7.5.0 Released: dynamic import and F# pipelines
  • The Babel Podcast
  • 7.4.0 Released: core-js 3, static private methods and partial application
  • 7.3.0 Released: Named capturing groups, private instance accessors and smart pipelines
  • 7.2.0 发布:私有实例方法(Private Instance Methods)
  • 在 Babel 中支持 TC39 标准的装饰器
  • 7.1.0 Released: Decorators, Private Static Fields
  • Babel 7 发布
  • Removing Babel's Stage Presets
  • What's Happening With the Pipeline (|>) Proposal?
  • Announcing Babel's New Partnership with trivago!
  • On Consuming (and Publishing) ES2015+ Packages
  • Nearing the 7.0 Release
  • Babel Turns Three
  • Planning for 7.0
  • Zero-config code transformation with babel-plugin-macros
  • Contributing to Babel: Three Lessons to Remember
  • Personal Experiences at Babel #1 — A PR with Unusually High Number of Reviews
  • Babel and Summer of Code 2017
  • Upgrade to Babel 7 (moved)
  • Upgrade to Babel 7 for Tool Authors (WIP)
  • 6.23.0 Released
  • The State of Babel
  • 6.19.0 Released
  • 6.18.0 Released
  • 6.16.0 Released
  • Babili (babel-minify)
  • 6.14.0 Released
  • Babel Doctor
  • Setting up Babel 6
  • 6.0.0 Released
  • React on ES6+
  • Function Bind Syntax
  • 5.0.0 Released
  • Babel 喜爱 React
  • 并非出生而逐渐走向灭亡
  • 2to3
  • 6to5 + esnext

7.16.0 发布: ESLint 8 和 TypeScript 4.5

October 29, 2021

Babel Team

我们刚刚发布了 Babel 7.16.0!

此版本默认启用 类静态初始化块。它不仅支持 管道操作符 提案的新变体,还提升了对 TypeScript 4.5 的兼容。

此外,@babel/eslint-parser 现已支持 ESLint 8.

你可以 在 GitHub 上 阅读完整的更新日志。

如果你或你的公司希望支持 Babel 和 JavaScript 的发展,但不知道该如何资助我们,你可以在我们的 Open Collective上给我们捐款,比这更好的方式是,直接与我们合作实现 新的 ECMAScript 提案!作为一个靠志愿者驱动的项目,我们依靠社区的支持,来资助我们更努力地为广泛的 JavaScript 用户提供更好的支持。如果你想讨论更多内容,请联系 team@babeljs.io!

亮点

默认启用类静态初始化块 (#13713)

class MyClass {
  static {
    doSomeInitialization(MyClass);
    console.log("MyClass initialized!");
  }
}

八月份进入第 4 阶段 的静态初始化块,现在在 @babel/parser 和 @babel/preset-env 中默认启用。

如果你使用的是 classStaticBlock 解析器插件,或是 @babel/plugin-syntax-class-static-block,你可以安全地将它们从配置中移除。

如果你已经在使用 @babel/preset-env,你现在可以从你的配置中删除 @babel/plugin-proposal-class-static-block。

TypeScript 4.5 特性 (#13802, #13838)

TypeScript 4.5 引入了用于将导入标记为 type-only 的新语法:你可以标记单个说明符,而不是标记整个 import 语句:

// TypeScript 4.4
import type { Foo } from "my-module";
import { fooInstance } from "my-module";

// TypeScript 4.5
import { type Foo, fooInstance } from "my-module";

它还支持两个新的文件扩展名:.mts 和 .cts,即 .mjs 和 .cjs 的镜像。在启用 @babel/preset-typescript 的情况下将 .mts 或 .cts 文件传递给 Babel 时,它会使用文件扩展名来检测所需的源类型("module" 或 "script")。

默认情况下,.mts 和 .cts 文件不能包含 JSX 代码,因为它们不能包含与 JSX 会有歧义的 TypeScript 批注(<Type> cast 和 <T>() => {})。

你可以 在他们的博客上 阅读完整的 TypeScript 4.5 发布博文。

^ Hack-style 管道的主题 token (#13749)

管道操作符 提案的拥护者正在考虑 各种主题 token(对上一个管道步骤中的值的引用)。

@babel/plugin-proposal-pipeline-operator(和 "pipelineOperator" 解析器插件)现在支持其中三个:#, ^ 和 %。

let values = getNames()
  |> ["default"].concat(^)
  |> await loadValues(^);

你可以使用 proposal: "hack" 选项来启用当前版本的管道操作符提案,也可以使用 topicToken: "^" 选择主题 token:

{
  "plugins": [
    ["@babel/plugin-proposal-pipeline-operator", {
      "proposal": "hack",
      "topicToken": "^"
    }]
  ]
}

@babel/eslint-parser 中的 ESLint 8 支持 (#13782)

@babel/eslint-parser 现已支持 ESLint 8:你可以更新你的 "eslint" 依赖,它就会正常工作。

如果你是 ESLint 插件作者,注意类字段和私有方法在 AST 当使用 ESLint 7 时,它们遵循 Babel AST shape;当使用 ESLint 8 时,它们遵循 ESLint 和 ESTree 规范。这是因为 ESLint 从 ESLint 8 开始引入了对这些新的类特性的支持。

Recent Posts
  • 亮点
    • 默认启用类静态初始化块 (#13713)
    • TypeScript 4.5 特性 (#13802, #13838)
    • ^ Hack-style 管道的主题 token (#13749)
    • @babel/eslint-parser 中的 ESLint 8 支持 (#13782)
Babel 中文文档
文档
学习 ES2015
社区
视频用户Stack OverflowSlack 频道Twitter
更多
博客GitHub 组织GitHub 仓库Website 仓库旧版网址 6.x旧版网址 5.x