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

2to3

January 27, 2015

James Kyle

过去几周,我们看到 6to5 项目有很多动态;每天在世界各个角落都有成千上万的人在下载。在过去一个月中,已经关闭 200 多个 issue。从 2.0 发布以来,已经有 867 次 commit(提交)、60 个 minor(次要版本) 和 patch(补丁版本) 发布。它的下载量是 npm 下载量最多的 packages 中的前 1%,仅在上个月就有近 100k 的下载量。

今天我们将发布 3.0。

注意: 6to5 不保留主要版本(major)的错误修复(bug fixes)或新的向后兼容功能(new backwards compatible features)。下面列出的一些功能来自之后的一些 2.x 版本。

Loose Mode(松散模式)

6to5 非常重视它所做一切的规范兼容性。有时,规范周围有许多复杂的边缘用例,但并不影响大多数代码。

所以我们添加了 Loose Mode(松散模式) 来忽略其中一些边缘用例,以便创建更清晰、更简短、更快速的执行输出。

例如,在构造函数中调用 super() 通常会被编译为:

function Foo() {
  _get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this);
}

而在 Loose Mode 下,会编译为:

function Foo() {
  Bar.call(this);
}

在使用 Loose Mode 之前,你应该意识到它不完全对齐规范,如果你没有预先知道这些不一致,可能会导致代码不兼容。查看 文档 以获取更多信息。

性能改善

在过去的几周里,@gaearon 做了一些惊人的工作,将 6to5 编译时间缩短了 200% 以上。这些改进对我们来说极其重要,我们很高兴看到社区成员做出如此巨大的贡献。

演示平台:锤形运算符(mallet operator)

如同在 Ruby 和 CoffeeScript 中看到过的锤形运算符,允许你根据其值是 falsy 或 非falsy 来有条件地分配值。

a ||= b

行为如下

if (!a) a = b;

这个功能来自 @jridgewell。我们鼓励提案作者挺身而出,以便将他们的想法体现在所有最新的语言和 API 功能中。

自包含性(selfContained)

我们还推出了一个新的可选 transformer,它可以消除对 polyfill 的需求,并绕过所有 6to5 注意事项。它会自动为 ES6 静态方法和内置函数添加别名,并在你使用 async function 或 generator 时引用 regenerator。这对于一些库非常有用,而无需污染全局作用域。

这将替换 coreAliasing 转换和 includeRegenerator 选项。查看 文档 以获取更多信息。

划分命名空间后的 transformer(namespaced transformers)

在 3.0 中,我们重新命名了所有 transformer,不仅是保持一致性,而是为了将它们划分为 namespace(命名空间)。

例如,我们已将所有 es7 transformer 重新命名为 es7.comprehensions 或 es7.objectSpread,因此如果你想将所有 es7 transformer 列入黑名单,可以直接:

$ 6to5 --blacklist es7

关于重新命名后的 transformers 的完整列表,请查看 Changelog。


由于有着许多全新功能和错误修复,使 v3 成为一个出色的版本。请务必在 Changelog 中查看所有内容。

我们要感谢所有参与 6to5 社区的人,特别是那些为 3.0 发布做出贡献的人。

未来看起来充满光明。

— 6to5 团队

Recent Posts
Babel 中文文档
文档
学习 ES2015
社区
视频用户Stack OverflowSlack 频道Twitter
更多
博客GitHub 组织GitHub 仓库Website 仓库旧版网址 6.x旧版网址 5.x