v6.16.0
v6.16.0 (2016-09-28)
If you are seeing something like:
No compatible version found: babel-types@^6.16.0
runnpm view babel-types dist-tags
to be sure
Babel 6.16: Happy 2nd Birthday 馃巶 !
Blog post here: http://babeljs.io/blog/2016/09/28/6.16.0
馃憮 Spec Compliancy
babel-core
,babel-generator
,babel-helper-remap-async-to-generator
,babel-helpers
,babel-plugin-transform-async-generator-functions
,babel-types
,babel-preset-stage-2
, ...- #3473 via #4576 Implement support for async generator functions and for-await statements. (@zenparsing)
This change implements the async iteration proposal, currently at stage 2 (and pushing to stage 3 at the current TC-39 meeting). It includes the following features:
- Transforms async generator functions (
async function* g() { }
) to wrapped generator functions, similar to the current async-to-generator transform.
async function* agf() {
this;
await 1;
yield 2;
return 3;
}
- Transforms
for-await
statements into for loops containing yield expressions.
async function f() {
for await (let x of y) {
g(x);
}
}
Example Usage
async function* genAnswers() {
var stream = [ Promise.resolve(4), Promise.resolve(9), Promise.resolve(12) ];
var total = 0;
for await (let val of stream) {
total += await val;
yield total;
}
}
function forEach(ai, fn) {
return ai.next().then(function (r) {
if (!r.done) {
fn(r);
return forEach(ai, fn);
}
});
}
var output = 0;
return forEach(genAnswers(), function(val) { output += val.value })
.then(function () {
assert.equal(output, 42);
});
babel-core
,babel-generator
,babel-plugin-transform-class-properties
,babel-template
,babel-traverse
,babel-types
Parser support was added in babylon@6.11.0 with babel/babylon#121
// Example
class Foo {
[x]
['y']
}
class Bar {
[p]
[m] () {}
}
Parser support was added in babylon@6.10.0 with babel/babylon#104
// Example
var a : {| x: number, y: string |} = { x: 0, y: 'foo' };
馃殌 New Feature
Babel will now also take the options: parserOpts
and generatorOpts
(as objects).
parserOpts
will pass all properties down to the default babylon
parser. You can also pass a parser
option to substitute for a different parser.
This will allow passing down any of babylon's
options:
{
"parserOpts": {
"allowImportExportEverywhere": true,
"allowReturnOutsideFunction": true,
"sourceType": "module",
"plugins": ["flow"]
}
}
Another use case (the main reason for doing this), is to be able to use recast with Babel.
{
"parserOpts": {
"parser": "recast"
},
"generatorOpts": {
"generator": "recast"
}
}
{
presets: ["@org/babel-preset-name"], // actual package
presets: ["@org/name"] // shorthand name
}
useBuiltIns
- Do not use Babel's helper's and just transform to use the built-in method (Disabled by default).
{
"plugins": [
["transform-object-rest-spread", { "useBuiltIns": true }]
]
}
// source
z = { x, ...y };
// compiled
z = Object.assign({ x }, y);
babel-code-frame
is a standalone package that we use in Babel when reporting errors.
Now there is an option to specify the number of lines above and below the error
1 | class Foo {
> 2 | constructor()
| ^
3 | }
babel-core
,babel-preset-es2015
,babel-preset-es2016
,babel-preset-es2017
,babel-preset-latest
,babel-preset-react
,babel-preset-stage-0
,babel-preset-stage-1
,babel-preset-stage-2
,babel-preset-stage-3
We previously made presets with commonjs exports
module.exports = {
plugins: [
require("babel-plugin-syntax-trailing-function-commas")
]
};
Now you can use export default as well
import transformExponentiationOperator from "babel-plugin-transform-exponentiation-operator";
export default {
plugins: [
transformExponentiationOperator
]
};
馃悰 Bug Fix
babel-helpers
,babel-plugin-transform-es2015-typeof-symbol
- #3686 Fix
typeof Symbol.prototype
. (@brainlock)
- #3686 Fix
// `typeof Symbol.prototype` should be 'object'
typeof Symbol.prototype === 'object'
babel-cli
- #3456 Use the real sourcemap API and handle input sourcemaps - Fixes #7259. (@loganfsmyth)
- #4507 Only set options in cli if different from default. (@danez)
Fix an issue with defaults not being overidden. This was causing options like comments: false
not to work correctly.
- #4508 Support custom ports for V8 --inspect. (@andykant)
- #4562 Fixes #2299: Prevent REPL from printing implicit 'use strict'. (@hzoo)
babel-plugin-transform-es2015-function-name
,babel-traverse
- #4524 Fix default export with arrows and function naming. (@danharper)
// wasn't exporting correctly before
export default ({ onClick }) => {
return <div onClick={() => onClick()}></div>;
}
babel-plugin-transform-es2015-modules-commonjs
export default class {};
// wasn't correctly transforming to
exports["default"] = class {}
// with the es3-tranforms
babel-plugin-transform-flow-strip-types
,babel-types
// <X> wasn't stripped out
const find = <X> (f: (x:X) => X, xs: Array<X>): ?X => (
xs.reduce(((b, x) => b ? b : f(x) ? x : null), null)
)
babel-generator
,babel-plugin-transform-flow-comments
- #4504 Flow: Fix generating arrow functions with param. (@danharper)
babel-register
babel-core
- #4570 Fix fileName options passed to babylon. (@DatenMetzgerX)
babel-traverse
- #4534 Fix issue with minified libraries and code coverage. (@withinboredom)
babel-plugin-transform-es2015-destructuring
We noticed that we can not make this optimizations if there are function calls or member expressions on the right hand side of the assignment since the function call or the member expression (which might be a getter with side-effect) could potentially change the variables we are assigning to.
[x, y] = [a(), obj.x];
// was tranforming to
x = a();
y = obj.x;
// now transforms to
var _ref = [a(), obj.x];
x = _ref[0];
y = _ref[1];
babel-types
- #4587 Prevent flow-strip-types/flow-comments from removing entire ClassProperty. (@danharper)
馃拝 Polish
babel-code-frame
Before
After
- `babel-core` - [#4517](https://github.com//pull/4517) If loading a preset fails, show its name/path (#4506). ([@motiz88](https://github.com/motiz88)) - `babel-helper-replace-supers` - [#4520](https://github.com//pull/4520) Remove unused `thisReference` argument to `getSuperProperty`. ([@eventualbuddha](https://github.com/eventualbuddha)) - `babel-generator` - [#4478](https://github.com//pull/4478) babel-generator: Ensure ASCII-safe output for string literals. ([@mathiasbynens](https://github.com/mathiasbynens)) - `babel-core`, `babel-plugin-transform-es2015-arrow-functions`, `babel-plugin-transform-es2015-destructuring`, `babel-plugin-transform-es2015-modules-commonjs`, `babel-plugin-transform-es2015-parameters` - [#4515](https://github.com//pull/4515) Flip default parameter template. ([@jridgewell](https://github.com/jridgewell)) - `babel-core`, `babel-helpers` - [#3653](https://github.com//pull/3653) Removed unnecessary 'return' statements. ([@ksjun](https://github.com/ksjun))馃彔 Internal
Cleanup tests, remove various unused dependencies, do not run CI with only readme changes.
babel-plugin-transform-es2015-modules-amd
,babel-plugin-transform-es2015-modules-commonjs
,babel-plugin-transform-es2015-modules-umd
- #4543 Remove duplicate default error. (@kaicataldo)
babel-generator
,babel-plugin-transform-es2015-modules-amd
,babel-plugin-transform-es2015-modules-commonjs
,babel-plugin-transform-es2015-modules-systemjs
,babel-plugin-transform-es2015-modules-umd
,babel-plugin-transform-flow-strip-types
- #4538 Fix tests with duplicate named exports. (@kaicataldo)
babel-plugin-transform-es2015-function-name
- #4532 Add tests for other module formats, from #4524. (@danharper)
babel-plugin-transform-es2015-parameters
,babel-traverse
babel-polyfill
babel-preset-es2015
- #4501 Remove ES2015 tests than do not parse in ES2016. (@TimothyGu)
babel-plugin-transform-regenerator
babel-code-frame
babel-helper-transform-fixture-test-runner
- Other
Commiters: 20
First PRs!
- Alberto Piai (brainlock)
- Andy Kant (andykant)
- Basil Hosmer (bhosmer)
- Bo Borgerson (gigabo)
- Dan Harper (danharper)
- Kay J. (ksjun)
- Maxime Thirouin (MoOx)
- Micha Reiser (DatenMetzgerX)
- Moti Zilberman (motiz88)
- Rob Landers (withinboredom)
- Timothy Gu (TimothyGu)
- zenparsing (zenparsing)