Upgrade to Babel 7 for Tool Authors (WIP)

Posted Mar 1, 2017 by Sven SAULEAU, Henry Zhu

Refer users to this document for those that create tools that depend on Babel (such as Babel plugins).

Also check out the User Upgrade Guide for other relevant changes.

All Babel packages

Support for Node.js 0.10 and 0.12 has been dropped high

Dropped use of add-module-exports plugin on Babel packages medium

This had to be used earlier to prevent a breaking change with our exports.

If you import a Babel package in a library you may need to use .default when using require rather than import.

babel-core

The publicly exposed but undocumented Pipeline class has been removed. Best to use the transformation methods exposed from babel-core directly babel/babel#5376.

The babel.util.* helper methods have been removed, and util.EXTENSIONS has been moved to babel.DEFAULT_EXTENSIONS babel/babel#5487.

Calls to babel.transform or any other transform function may return null if the file matched an ignore pattern or failed to match an only pattern babel/babel#5487.

The opts.basename option exposed on state.file.opts has been removed. If you need it, best to build it from opts.filename yourself babel/babel#5467.

Babylon

AST changes high

Flow: Node renamed from ExistentialTypeParam to ExistsTypeAnnotation #322

type Maybe<T> = _Maybe<T, *>;

Flow: Node renamed from NumericLiteralTypeAnnotation to NumberLiteralTypeAnnotation babel/babylon#332

type T = 0;

Flow: New node Variance which replaces the string value of the variance field on several nodes (TODO: be more specific here) babel/babylon#333

class A {+p:T}
class A {-p:T}

Flow: ObjectTypeIndexer location info matches Flow’s better babel/babylon#228

Babylon was including the semicolon in the location, whereas Flow didn’t.

var a: { [a: number]: string; [b: number]: string; };

Node ForAwaitStatement has been removed #349

An await property is defined instead.

interface ForOfStatement <: ForInStatement {
  type: "ForOfStatement";
  await: boolean;
}
async function f() {
  for await (let x of y);
}

Nodes RestProperty and SpreadProperty are removed in favor of reusing RestElement and SpreadElement #384

The actual syntax for both is the same: .... Before we differentiated the usage of them based on if it was used in an object or in an array.

See our upgrade PR for Babel and the Babylon AST spec for more information.

Removed the * plugin option babel/babylon#301 low

This was first added in v6.14.1 (Nov 17, 2016) so it’s unlikely anyone was using this.

This catch-all option was removed; instead you should specifically decide which plugins you want to activate.

We thought it would be a good idea for tools so they wouldn’t have to constantly update their config but it also means we can’t easily make a breaking change.

Before:

babylon.parse(code, {
  plugins: [ "*" ]
})

You can get the old behavior using:

babylon.parse(code, {
  plugins: [
    "asyncGenerators",
    "classProperties",
    "decorators",
    "doExpressions",
    "dynamicImport",
    "exportExtensions",
    "flow",
    "functionBind",
    "functionSent",
    "jsx",
    "objectRestSpread",
  ]
})

See Babylon’s plugin options.

Removed classConstructorCall plugin #291 low