Skip to main content

2to3

· 6 min read

过去几个星期,我们看到 6to5 上有很多活动;每天都有来自世界各地的人下载它。过去一个月,已经关闭了 200 多个问题。自 2.0 版本发布以来,已有 867 次提交和 60 次小版本及修补版本发布。现在它已经跻身 npm 下载量最多的前 1%,仅上个月就有近 10 万次下载。

🌐 These past few weeks we’ve seen lots of activity on 6to5; thousands are downloading it every day from all corners of the world. In the past month, over 200 issues have been closed. Since the 2.0 release, there have been 867 commits and 60 minor and patch releases. It’s now among the top 1% of most downloaded packages on npm, with nearly 100k downloads in the last month alone.

今天我们发布3.0了。

🌐 Today we are releasing 3.0.

注意: 6to5 不会为了大版本发布而保留 bug 修复或新的向后兼容功能。列出的一些功能来自后续的 2.x 版本。

松散模式​

🌐 Loose Mode

6to5 在它所做的所有事情上都非常专注于规范的合规性。有时候,规范要求在一些不会影响大多数代码的边缘情况处理上非常复杂。

我们增加了宽松模式,用来忽略其中一些边缘情况,从而创建更清晰、更小巧、执行更快的输出。

🌐 We’ve added Loose Mode for ignoring some of these edgecases in order to create cleaner, smaller, and faster executing output.

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

🌐 For example, calling super() inside a constructor would normally be compiled to:

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

不过,用宽松模式它会被编译为:

🌐 However, with Loose Mode it is compiled to:

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

在使用松散模式之前,你应该知道它并不完全符合规范,如果不注意这些不一致,可能会导致代码不兼容。更多信息请查看文档。

🌐 Before you use Loose Mode, you should be aware that it doesn't line up with the spec completely, it may lead to incompatible code if you aren't aware of these inconsistencies. Check out the docs for more info.

性能提升​

🌐 Performance Improvements

在过去的几周里 @gaearon 在提升 6to5 编译速度方面做了一些惊人的工作,提升幅度超过了 200%。这种改进对我们来说非常重要,我们很高兴看到社区成员做出如此出色的贡献。

🌐 In the past few weeks @gaearon has done some amazing work to improve 6to5 compilation time by over 200%. These kinds of improvements are extremely important to us and we’re happy to see such great contributions from community members.

游乐场:大槌运算符​

🌐 Playground: Mallet Operator

正如在 Ruby 和 CoffeeScript 中所看到的,Mallet 操作符允许你根据值的假值特性有条件地进行赋值。

🌐 As seen in Ruby and CoffeeScript, the Mallet operator allows you to conditionally assign values based on their falsy-ness.

JavaScript
a ||= b

会表现得像

🌐 will behave like

JavaScript
if (!a) a = b;

这条信息来自 @jridgewell。我们鼓励提案作者积极提出自己的想法,以便让这些想法与所有最新的语言和 API 功能一起实现。

🌐 This one comes to you from @jridgewell. We encourage proposal authors to come forward in order to get their ideas implemented alongside all of the latest language and API features.

selfContained​

我们还引入了一个新的可选转换器,它无需使用 polyfill,并且可以绕过所有 6to5 的 注意事项。它会自动为 ES6 静态方法和内置对象创建别名,并在你使用异步函数或生成器时包含 regenerator。这对于不想污染全局作用域的库来说非常棒。

🌐 We’ve also introduced a new optional transformer that negates the need for a polyfill and bypasses all 6to5 caveats. It will automatically alias ES6 static methods and built-ins as well as include regenerator whenever you use async functions or generators. This is great for libraries that don't want to pollute the global scope.

这会替代 coreAliasing 转换和 includeRegenerator 选项。想了解更多信息,请查看文档。

🌐 This replaces the coreAliasing transform and the includeRegenerator option. Check out the docs for more info.

命名空间转换器​

🌐 Namespaced Transformers

在3.0中,我们给所有的转换器都改了名字,不仅是为了统一,也为了给它们加上命名空间。

🌐 In 3.0, we’ve renamed all of the transformers, not just for consistency but in order to namespace them.

例如,我们已经将所有的 es7 转换器重命名为类似 es7.comprehensions 或 es7.objectSpread 的东西,所以如果你想将所有 es7 转换器加入黑名单,你可以直接:

🌐 For example, we’ve renamed all of the es7 transformers to be things like es7.comprehensions or es7.objectSpread so if you would like to blacklist all of the es7 transformers you can simply:

Shell
$ 6to5 --blacklist es7

要查看所有已重命名的转换器,请参阅 更新日志。

🌐 For a full list of the renamed transformers see the Changelog.


v3 有许多新功能和错误修复,使其成为一个出色的版本。务必在 更新日志 中查看所有内容。

🌐 There are many new features and bug fixes that makes v3 an excellent release. Be sure to review them all in the Changelog.

我们想感谢所有参与 6to5 社区的人,尤其是那些为实现 3.0 做出贡献的人。

🌐 We’d like to thank everyone who has been involved in the 6to5 community and especially those who have contributed to making 3.0 happen.

未来一片光明。

🌐 The future is looking bright.

——6to5 团队