Skip to main content

今天发布 Babel 8:仅支持 ESM,放弃 ES5 默认,同时提供顺畅的迁移路径

· 15 min read

今天我们发布了 Babel 8。距离我们发布 Babel 7 已经有 8 年了。这绝不是没有原因的。

🌐 Today we are releasing Babel 8. It's been 8 years since we released Babel 7. And that's not without reason.

在过去的八年里,JavaScript 生态系统发生了很大变化。除了 Babel,SWC 和 Oxc 也成为了替代的 JavaScript 编译器,而 JavaScript 语言本身也随着新特性和提案的发展而演变(其中很多在标准化之前都曾在 Babel 中进行原型设计和测试!)。

🌐 Over these past 8 years, the JavaScript ecosystem has changed significantly. In addition to Babel, SWC and Oxc have emerged as alternative JavaScript compilers, and the JavaScript language itself has evolved with new features and proposals (many of which were prototyped and tested in Babel before being standardized!).

你可能会想,Babel 因此变得不那么重要了。但现实并非如此。Babel 的下载量从 2018 年每周 170 万次增长到了本周(2026 年 6 月)每周 6.51 亿次。在过去的一年里,Babel 的每周下载量翻了一番。

🌐 You might imagine that Babel became less relevant because of that. But reality begs to differ. Babel has grown from 1.7 million weekly downloads in 2018, to 651 million weekly downloads this week (Jun 2026). Babel has doubled its weekly download counts in the last year.

这种使用方式对我们的用户带来了巨大的责任。Babel 在全球的许多构建管道中都有使用,即使是很小的破坏性更改,也可能导致数十万开发者无法发布他们的代码。这就是为什么我们在过去八年里没有做过带有破坏性更改的重大版本更新,也就是为什么我们对 Babel 8 采取非常谨慎的做法。

🌐 This usage comes with a huge responsibility to our users. Babel is used in so many build pipelines across the world that even minor breaking changes can cause hundreds of thousands of developers to be blocked from shipping their code. That's why we've not done a major release with breaking changes in 8 years, and why we are taking a very careful approach to Babel 8.

7.29.0 发布:最后一个 Babel 7 小版本

· 7 min read

Babel 7.29.0 发布啦!

🌐 Babel 7.29.0 is out!

这是 Babel 7 的最后一个小版本,因为我们正准备发布 Babel 8.0.0。Babel 8.0.0-rc 今天也发布了:快去试试吧!

🌐 This is the last minor release of Babel 7, as we are getting ready to release Babel 8.0.0. Babel 8.0.0-rc is also out today: go try it out!

这个版本增加了通过在 <script> 元素上使用 data-target 属性来定义 @babel/standalone 的转译目标的支持。它还为 @babel/standalone 增加了对 @babel/core 异步 API 的支持。

🌐 This release include support for defining transpilation targets in @babel/standalone through a data-target attribute on <script> elements. It also adds support for the @babel/core async API to @babel/standalone.

这两项改动都是为了让从 Babel 7 迁移到 Babel 8 更加轻松。

🌐 Both of these changes are meant to ease the migration from Babel 7 to Babel 8.

你可以在 GitHub 上阅读完整的更新日志。如果你已经在使用 Babel 8 测试版,所有 7.28.0 的新功能都包含在 v8.0.0-rc.1 中。

🌐 You can read the whole changelog on GitHub. If you are already using Babel 8 beta, all the new 7.28.0 features are included in v8.0.0-rc.1.

7.28.0 发布:`babel.config.ts`、显式资源管理和丢弃绑定提案

· 6 min read

Babel 7.28.0 发布啦!

🌐 Babel 7.28.0 is out!

此版本包括对 babel.config.ts 和 babel.config.mts 的支持,ES2026 显式资源管理功能,丢弃绑定提案 以及 sourceType: "commonjs" 选项。

🌐 This release includes support for babel.config.ts and babel.config.mts, the ES2026 Explicit Resource Management feature, the discard binding proposal, and the sourceType: "commonjs" option.

你可以在 GitHub 上阅读完整的更新日志。如果你已经在使用 Babel 8 测试版,所有新的 7.28.0 功能都包含在 v8.0.0-beta.1 中。

🌐 You can read the whole changelog on GitHub. If you are already using Babel 8 beta, all the new 7.28.0 features are included in v8.0.0-beta.1.

宣布 Babel 8 测试版

· 5 min read

自从第一次 Babel 8 alpha 版本发布(8.0.0-alpha.0)几乎两年后,我们终于准备好了。

🌐 After almost two years since the first Babel 8 alpha release (8.0.0-alpha.0), we are finally ready.

我们计划在 Babel 8 中包含的所有重大更改都已经完成,而且我们也清理了多年来积累的许多技术债务,这些债务在 Babel 7 的生命周期内无法移除。

🌐 All the breaking changes we were planning to include in Babel 8 are done, and we have removed a lot of the technical debt we've accumulated over the years and were unable to remove during Babel 7's lifetime.

我们现在需要在真实项目中测试它,以确保我们没出错。我们从早期 alpha 版本开始就已经用 Babel 8 转译自己的代码了,但只有一个预发布用户还不够。😉

🌐 We now need to test it in real projects to make sure we got everything right. We have been transpiling our own code using Babel 8 since early alpha versions, but one prerelease user is not enough. 😉

7.27.0 发布:更好的生态系统协调

· 5 min read

Babel 7.27.0 发布啦!

🌐 Babel 7.27.0 is out!

这个版本没有包含任何重大新功能,但它更好地让 Babel 的行为与标准 JavaScript 和其他工具保持一致。

🌐 This release doesn't include any significant new feature, but it better aligns Babel's behavior with standard JavaScript and other tools.

代码打印器现在也会默认打印正确的 import attributes 语法,而不用让用户专门去启用某个选项。

🌐 The code printer will now also print the correct import attributes syntax by default, rather than expecting its users to explicitly enable an option for it.

我们还调整了 @babel/preset-typescript 的 rewriteImportExtensions 选项的行为,以修复与 TypeScript 的 --rewriteRelativeImportExtensions 相比的一些差异。

🌐 We also tweaked the behavior of @babel/preset-typescript's rewriteImportExtensions option, to fix some differences when compared to TypeScript's --rewriteRelativeImportExtensions.

最后,我们在 @babel/parser 中更新了 estree 兼容插件,以便为由 decorators 第三阶段提案引入的 accessor foo = "val" 类属性生成 AccessorProperty 节点。需要注意的是,为了向后兼容,只有在启用 estree 插件的 classFeatures 选项时,@babel/parser 才会为类特性生成 ESTree 兼容的 AST。

🌐 Lastly, we updated our estree compatibility plugin in @babel/parser to generate AccessorProperty nodes for accessor foo = "val" class properties, introduced by the decorators stage 3 proposal. Note that, for legacy compatibility reasons, @babel/parser only generates an ESTree-compatible AST for class features when the classFeatures option of the estree plugin is enabled.

有很多更改可能对插件作者有帮助:你可以在 GitHub 上阅读完整的更新日志。

🌐 There are multiple changes that may benefit plugin authors: you can read the whole changelog on GitHub.

7.26.0 发布:默认启用阶段4功能,还有一个新的实验性代码打印器

· 7 min read

Babel 7.26.0 刚刚发布了!

🌐 Babel 7.26.0 was just released!

它默认启用了两个在上次 TC39 会议中成为标准的 ECMAScript 提案的支持,import 属性 和 内联正则表达式修饰符,以及对 Flow 枚举 的解析。

🌐 It enables by default support of two ECMAScript proposals that become standard in the last TC39 meeting, import attributes and inline regular expression modifiers, as well as parsing of Flow enums.

Babel 现在也允许插件提供异步的 pre/post 钩子,并且有一个 [实验模式](TODO: Link) 可以在生成转换后的输出时保留标记的位置。

🌐 Babel now also allows plugins to provide asynchronous pre/post hooks, and has an [experimental mode](TODO: Link) to preserve tokens' positions when generating the transformed output.

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

🌐 You can read the whole changelog on GitHub.

7.25.0 发布:Safari 错误修复和重复命名捕获组

· 6 min read

Babel 7.25.0 发布啦!

🌐 Babel 7.25.0 is out!

@babel/preset-env 现在默认支持正则表达式的 重复命名捕获组 提案,同时修复了在 Safari 上使用类字段的一个 bug。这个版本还改进了将 JSON 模块导入 编译为 CommonJS 的支持,并为 @babel/node 的 --eval 模式添加了对配置文件的支持。

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

🌐 You can read the whole changelog on GitHub.

7.24.0 发布:装饰器更新和 JSON 模块导入

· 7 min read

Babel 7.24.0 发布啦!

🌐 Babel 7.24.0 is out!

我们更新了我们的 Decorators 实现,以匹配提案的最新版本,并改进了我们转换类私有字段和方法的方式。我们还增加了在浏览器和 Node.js 中导入 JSON 模块 的支持,这是一个依赖 Import Attributes 的旧 Stage 3 提案。

🌐 We updated our Decorators implementation to match the latest version of the proposal, and we improved the way we transform class private fields and methods. We also added support for importing JSON modules in browsers and Node.js, an older Stage 3 proposal depending on Import Attributes.

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

🌐 You can read the whole changelog on GitHub.

CVE-2023-45133:在 Babel 中发现任意代码执行漏洞

· 18 min read

在2023年10月10日,我偶然发现了Babel中的一个任意代码执行漏洞,该漏洞随后被分配了标识符CVE-2023-45133。在这篇文章中,我将带你了解发现和利用这个有趣漏洞的整个过程。

🌐 On October 10th, 2023, I stumbled upon an arbitrary code execution vulnerability in Babel, which was subsequently assigned the identifier CVE-2023-45133. In this post, I’ll walk you through the journey of discovering and exploiting this intriguing flaw.

7.23.0 发布:Decorator 元数据和许多新的 `import` 功能!

· 12 min read

我们刚刚发布了 Babel 7.23.0!🎉

🌐 We just released Babel 7.23.0! 🎉

它包括对 Decorator Metadata、Source Phase Import、Deferred Import Evaluation 和 Optional Chaining Assignment 提案的转换支持。我们还更新了解析器以支持新的 TypeScript 5.2 版本,并增加了一个转换选项,让你可以在 TypeScript 导入中使用 .ts 扩展。

🌐 It includes transform support for the Decorator Metadata, Source Phase Import, Deferred Import Evaluation, and Optional Chaining Assignment proposals. We also updated our parser to support the new TypeScript 5.2 version, and added a transform option to let you use the .ts extension within TypeScript imports.

除了发布7.23.0版本,我们最近还发布了第一个Babel 8测试版!

🌐 In addition to releasing version 7.23.0, we also recently published the first Babel 8 alpha release!

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

🌐 You can read the whole changelog on GitHub.