跳到主要内容

2to3

· 阅读需 3 分钟

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.

Today we are releasing 3.0.

Note: 6to5 doesn't hold onto bug fixes or new backwards compatible features for major releases. Some of the features listed are from later 2.x releases.

Loose Mode

6to5 is very focused on spec-compliancy in everything that it does. Sometimes the spec requires a lot of complexity around edgecases that don't affect most code.

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

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

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

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;

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

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.

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

Namespaced Transformers

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

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.


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

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.

— The 6to5 team