Skip to content

v6.16.0

Compare
Choose a tag to compare
@hzoo hzoo released this 28 Sep 19:45
· 9086 commits to main since this release

v6.16.0 (2016-09-28)

If you are seeing something like:
No compatible version found: babel-types@^6.16.0
run npm 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] () {}
}
  • babel-generator
    • #3702 flow plugin: generate exact object type annotations. (@bhosmer)

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-core, babel-generator
    • #3561 babel-core: add options for different parser/generator. (@hzoo)

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"
  }
}
  • babel-core
    • #4542 Add support for preset organization shortcuts. (@nkt)
{
  presets: ["@org/babel-preset-name"], // actual package
  presets: ["@org/name"] // shorthand name
}
  • babel-plugin-transform-object-rest-spread
    • #4491 object rest spread useBuiltIns option. (@hzoo)

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
    • #4561 babel-code-frame: add options for linesBefore, linesAfter. (@hzoo)

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
// `typeof Symbol.prototype` should be 'object'
typeof Symbol.prototype === 'object'
  • babel-cli

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
    • #4511 Fix UpdateExpression handling in es2015-modules-commonjs, resolve #4462. (@motiz88)
    • #4518 fix default exported classes without a name. (@danez)
export default class {};
// wasn't correctly transforming to
exports["default"] = class {}
// with the es3-tranforms
  • babel-plugin-transform-flow-strip-types, babel-types
    • #4521 Fix striping of typeParameters from arrow functions. (@danez)
// <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
  • babel-register
    • #3685 Allow overwritting of sourceRoot. (@danez)
    • #4577 babel-register: update source-map-support to latest. (@MoOx)
  • babel-core
  • babel-traverse
  • babel-plugin-transform-es2015-destructuring
    • #4552 Fix destructuring evaluation with call expressions. (@danez)

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
    • #4579 babel-code-frame: Highlight strings with green (not red). (@lydell)
    • #4572 Improve syntax highlighting colors. (@lydell)

Before

screen shot 2016-09-27 at 11 12 47 am

After

screen shot 2016-09-27 at 3 50 02 pm

- `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
  • 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
  • babel-plugin-transform-es2015-function-name
  • babel-plugin-transform-es2015-parameters, babel-traverse
    • #4519 Replace phabricator tickets with github ones in code comments. (@danez)
  • babel-polyfill
    • #3694 Use plain js to do the pre/postpublish for the polyfill. (@danez)
  • babel-preset-es2015
  • babel-plugin-transform-regenerator
  • babel-code-frame
    • #3699 babel-code-frame: babel-runtime not necessary. (@hzoo)
    • #3696 Satisfy the "space-infix-ops" eslint rule. (@gigabo)
  • babel-helper-transform-fixture-test-runner
    • #4560 Remove unused dependency babel-register. (@danez)
    • #3669 Do not include babel-register in test helper. (@danez)
  • Other

Commiters: 20

First PRs!