Skip to content

Instantly share code, notes, and snippets.

@xtuc
Last active February 1, 2018 22:11
Show Gist options
  • Save xtuc/1da8b38472cfd242c3e634b431b8818b to your computer and use it in GitHub Desktop.
Save xtuc/1da8b38472cfd242c3e634b431b8818b to your computer and use it in GitHub Desktop.
Upgrade guide for Babel 7

UPGRADE FROM 6.x to 7.0

Table of Contents

TODO

babel

Support for Node.js 0.10 and 0.12 has been dropped

We highly encourage you to use a newer version of Node.js since these versions are in end of maintenance.

Yarn

Along npm Babel supports Yarn. See Yarn's documentation on how to use it.

babylon

Trailing comma after rest parameter in objects is not allowed anymore

Before:

var { ...y, } = { a: 1};

This will now throw a SyntaxError.

After:

var { ...y } = { a: 1};

or:

var { ...y, b } = { a: 1};

babel-core

babel-core/register.js has been removed

Relying on babel-core/register is deprecated and will be removed in Babel 7.

Upgrade with Mocha:

mocha --compilers js:babel-core/register

to:

mocha --compilers js:babel-register

We need to add babel-register as a new dependecy:

npm install --save-dev babel-register

See babel-register documentation for more informations.

babel-preset-stage-3

babel-plugin-syntax-trailing-function-commas, babel-plugin-transform-async-to-generator and babel-plugin-transform-exponentiation-operator are moved into babel-preset-stage-4.

Babel recently created babel-preset-env which based on your environment use the right presets. If you have issue with this changes we suggest you using the env preset.

babel-plugin-transform-exponentiation-operator has been removed from this preset

Example:

let cubed = 2 ** 3;

If you rely on this syntax, we suggest you using rather the env preset.

babel-plugin-syntax-class-constructor-call

babel-plugin-syntax-class-constructor-call has been removed

TC39 decided to drop this proposal.

Before:

class Point {

  constructor(x, y) {
    this.x = x;
    this.y = y;
  }

  call constructor(x, y) {
    return new Point(x, y);
  }

}

let p1 = new Point(1, 2);
let p2 = Point(3, 4);

You can move your logic into the constructor or into a static method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment