Upgrade to Babel 8 (Integration)
Refer plugin developers or integration users to this document when upgrading to Babel 8.
Check out the v8-migration guide for other user-level changes.
AST Changes
JavaScript nodes
- Represent dynamic
import()
with anImportExpression
node (#15682, #16114).Migration: You are encouraged to test your Babel plugins with the new AST, starting from v7.23.0, specifying// Example input
import("foo", options);
// AST in Babel 7
{
type: "CallExpression",
callee: { type: "Import" },
arguments: [
StringLiteral("foo"),
Identifier("options")
]
}
// AST in Babel 8
{
type: "ImportExpression",
source: StringLiteral("foo"),
options: Identifier("options")
}{ parserOpts: { createImportExpressions: true } }
in the Babel config. For end users utilizing Babel plugins that rely on the legacyimport()
AST, it is possible to setcreateImportExpressions
tofalse
. Note that the Babel 7import()
AST is now considered deprecated, it does not support new ES features such as Source Phrase Imports. We will remove thecreateImportExpressions
parser option in Babel 9.
TypeScript nodes
Most of the changes to our TypeScript-specific AST nodes are to reduce the differences with the AST shape of the @typescript-eslint
project. This will make it easier to write ESLint rules that, when not depending on type information, can work both with @typescript-eslint/parser
and @babel/eslint-parser
.
-
Use an identifier for
TSTypeParameter.name
, rather than a plain string (#12829)input.ts// T is a TSTypeParameter
function process<T>(input: T): T {}
// AST in Babel 7
{
type: "TSTypeParameter",
name: "T",
}
// AST in Babel 8
{
type: "TSTypeParameter",
name: { type: "Identifier", name: "T" },
} -
Rename
parameters
toparams
andtypeAnnotation
toreturnType
inTSCallSignatureDeclaration
,TSConstructSignatureDeclaration
,TSFunctionType
,TSConstructorType
andTSMethodSignature
(#9231, #13709)TSCallSignatureDeclaration
interface Foo {
(x: number): string;
}
// AST in Babel 7
{
type: "TSCallSignatureDeclaration",
parameters: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
typeAnnotation: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
}
// AST in Babel 8
{
type: "TSCallSignatureDeclaration",
params: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
retutnType: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
}TSConstructSignatureDeclaration
interface Foo {
new (x: number): string;
}
// AST in Babel 7
{
type: "TSConstructSignatureDeclaration",
parameters: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
typeAnnotation: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
}
// AST in Babel 8
{
type: "TSConstructSignatureDeclaration",
params: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
retutnType: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
}TSMethodSignature
interface Foo {
foo(x: number): string;
}
// AST in Babel 7
{
type: "TSMethodSignature",
key: Identifier("foo"),
parameters: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
typeAnnotation: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
}
// AST in Babel 8
{
type: "TSMethodSignature",
key: Identifier("foo"),
params: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
retutnType: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
}TSFunctionType
type Bar = (x: number) => string;
// AST in Babel 7
{
type: "TSFunctionType",
parameters: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
typeAnnotation: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
}
// AST in Babel 8
{
type: "TSFunctionType",
params: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
retutnType: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
}TSConstructorType
type Bar = (x: number) => string;
// AST in Babel 7
{
type: "TSConstructorType",
parameters: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
typeAnnotation: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
}
// AST in Babel 8
{
type: "TSConstructorType",
params: [
{ type: "Identifier", name: "x", typeAnnotation: { type: "TSNumberKeyword" } }
],
retutnType: {
type: "TSTypeAnnotation",
typeAnnotation: { type: "TSStringKeyword" }
}
} -
Rename
typeParameters
totypeArguments
inCallExpression
,JSXOpeningElement
,NewExpression
,OptionalCallExpression
,TSInstantiationExpression
,TSTypeQuery
andTSTypeReference
(#16679, #17008, #17012, #17020)CallExpression
fn<string>()
// AST in Babel 7
{
type: "CallExpression",
callee: Identifier("fn"),
arguments: [],
typeParameters: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}
// AST in Babel 8
{
type: "CallExpression",
callee: Identifier("fn"),
arguments: [],
typeArguments: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}JSXOpeningElement
<Component<string>/>
// AST in Babel 7
{
type: "JSXOpeningElement",
name: JSXIdentifier("Component"),
attributes: [],
selfClosing: true,
typeParameters: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}
// AST in Babel 8
{
type: "JSXOpeningElement",
name: JSXIdentifier("Component"),
attributes: [],
selfClosing: true,
typeArguments: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}NewExpression
new Component<string>()
// AST in Babel 7
{
type: "NewExpression",
callee: Identifier("Component"),
arguments: [],
typeParameters: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}
// AST in Babel 8
{
type: "NewExpression",
callee: Identifier("Component"),
arguments: [],
typeArguments: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}OptionalCallExpression
fn?.<string>()
// AST in Babel 7
{
type: "OptionalCallExpression",
callee: Identifier("fn"),
arguments: [],
optional: true,
typeParameters: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}
// AST in Babel 8
{
type: "OptionalCallExpression",
callee: Identifier("fn"),
arguments: [],
optional: true,
typeArguments: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}TSInstantiationExpression
fn<string>
// AST in Babel 7
{
type: "TSInstantiationExpression",
expression: Identifier("fn"),
typeParameters: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}
// AST in Babel 8
{
type: "TSInstantiationExpression",
expression: Identifier("fn"),
typeArguments: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}TSTypeQuery
var arr: typeof Array<string>;
// AST in Babel 7
{
type: "TSTypeQuery",
exprName: Identifier("Array"),
typeParameters: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}
// AST in Babel 8
{
type: "TSTypeQuery",
exprName: Identifier("Array"),
typeArguments: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}TSTypeReference
var arr: Array<string>;
// AST in Babel 7
{
type: "TSTypeReference",
typeName: Identifier("Array"),
typeParameters: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}
// AST in Babel 8
{
type: "TSTypeReference",
typeName: Identifier("Array"),
typeArguments: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
} -
Rename
superTypeParameters
tosuperTypeArguments
inClassDeclaration
andClassExpression
(#16679, #16997)class X extends Y<string> {}
// AST in Babel 7
{
type: "ClassDeclaration",
id: Identifier("X"),
superClass: Identifier("Y"),
superTypeParameters: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
}
// AST in Babel 8
{
type: "ClassDeclaration",
id: Identifier("X"),
superClass: Identifier("Y"),
superTypeArguments: {
type: "TSTypeParameterInstantiation",
params: [{
type: "TSStringKeyword"
}]
}
} -
Split
typeParameter
ofTSMappedType
(#16733).In
TSMappedType
nodes, thetypeParameter
property is flattened askey
andconstraint
properties ofTSMappedType
itself.let map1: { [P in string]: number; };
// AST in Babel 7
{
type: "TSMappedType",
typeParameter: {
type: "TypeParameter",
name: Identifier("P"),
constraint: TSStringKeyword()
},
typeAnnotation: TSNumberKeyword(),
}
// AST in Babel 8
{
type: "TSMappedType",
key: Identifier("P"),
constraint: TSStringKeyword()
typeAnnotation: TSNumberKeyword(),
} -
Split
TSExpressionWithTypeArguments
intoTSClassImplements
andTSInterfaceHeritage
(#16731.The new nodes also use
typeArguments
instead oftypeParameters
(#17017).ClassDeclaration
class C implements X<T> {}
// AST in Babel 7
{
type: "ClassDeclaration",
id: Identifier("C"),
implements: [
{
type: "TSExpressionWithTypeArguments",
expression: Identifier("X"),
typeParameters: {
type: "TSTypeParameterInstantiation",
params: [TSTypeReference(Identifier("T"))]
}
}
],
body: ClassBody([]),
}
// AST in Babel 8
{
type: "ClassDeclaration",
id: Identifier("C"),
implements: [
{
type: "TSClassImplements",
expression: Identifier("X"),
typeArguments: {
type: "TSTypeParameterInstantiation",
params: [TSTypeReference(Identifier("T"))]
}
}
],
body: ClassBody([]),
}TSInterfaceDeclaration
interface I extends X<T> {}
// AST in Babel 7
{
type: "TSInterfaceDeclaration",
id: Identifier("I"),
extends: [
{
type: "TSExpressionWithTypeArguments",
expression: Identifier("X"),
typeParameters: {
type: "TSTypeParameterInstantiation",
params: [TSTypeReference(Identifier("T"))]
}
}
],
body: TSInterfaceBody([]),
}
// AST in Babel 8
{
type: "TSInterfaceDeclaration",
id: Identifier("I"),
extends: [
{
type: "TSInterfaceHeritage",
expression: Identifier("X"),
typeArguments: {
type: "TSTypeParameterInstantiation",
params: [TSTypeReference(Identifier("T"))]
}
}
],
body: TSInterfaceBody([]),
} -
Create
TSAbstractMethodDefinition
andTSPropertyDefinition
when bothestree
andtypescript
parser plugins are enabled (#16679, #17014)Migration: This breaking change is part of the efforts to libraries and ESLint plugins that can work both with
typescript-eslint
and@babel/eslint-parser
. For most Babel plugin developers you can safely ignore this change as it does not affect the typescript transform and codemod. That said, if you are trying to develop a custom ESLint rule with@babel/eslint-parser
, this change aligns the Babel AST to thetypescript-eslint
AST.
-
Don't generate
TSParenthesizedType
unlesscreateParenthesizedExpression
is enabled(#9546, #12608)input.tstype T = ({});
// Babel 8 with createParenthesizedExpression: true, and Babel 7
TSParenthesizedType { typeAnnotation: TSTypeLiteral { members: [] } }
// Babel 8 with createParenthesizedExpression: false
TSTypeLiteral { members: [] }Migration: If you need information about parentheses, specify the
createParenthesizedExpression
parser option.babel.config.json{ "parserOpts": { "createParenthesizedExpression": true } }
When
createParenthesizedExpression
isfalse
, you can also usenode.extra.parenthesized
to detect whethernode
is wrapped in parentheses.
API Changes
All packages
-
Disallow importing internal files (#14013, #14179).
Migration: Use the exported API only. If you are relying on Babel internals, please open an issue and let us know.
@babel/core
-
Disallow using
babel.transform
,babel.transformFile
,babel.transformFromAst
,babel.parse
,babel.loadOptions
,babel.loadPartialConfig
andbabel.createConfigItem
synchronously (#11110, #12695, #15869).Migration: The APIs above require a callback argument. If you are not providing a callback, please use their sync versions:
babel.transformSync
,babel.transformFileSync
,babel.transformFromAstSync
,babel.parseSync
,babel.loadOptionsSync
,babel.loadPartialConfigSync
andbabel.createConfigItemSync
.
@babel/generator
-
Remove
CodeGenerator
class (#16126)Migration: In Babel 8 the undocumented
CodeGenerator
class has been removed, please use the default exportedgenerate
function instead.- new CodeGenerator(ast).generate()
+ generate(ast)
@babel/types
-
Reject invalid identifier names in
t.identifier
builder (#10917).babel-plugin.js// Empty string is an invalid identifier name
t.identifier("");Migration: Call
t.identifier
with a valid name. -
Remove
Super
from theExpression
alias (#14750).A
Super
node representssuper
in super callsuper()
and super propertysuper.foo
. Assuper
can not be a standalone expression,t.isExpression(t.super())
will returnfalse
in Babel 8.Migration: Search usage of the
t.isExpression
andt.assertsExpression
functions, and of thet.Expression
type alias: if they need to also acceptSuper
nodes, update them accordingly.my-babel-plugin.js// Add `.foo` to an expression
- if (t.isExpression(path.node)) {
+ if (t.isExpression(path.node) || t.isSuper(path.node)) {
path.replaceWith(
t.memberExpression(
path.node,
t.identifier("foo")
))
}You don't have to update the usage if
super()
andsuper.foo
is not involved:my-babel-plugin.js// define an expression as a computed key of `foo`
if (t.isExpression(path.node)) {
path.replaceWith(
t.memberExpression(
t.identifier("foo"),
// `super` can not be a computed key, so we don't update `isExpression`
path.node,
/* computed */ true
))
} -
Require an
Identifier
node as the third argument oft.tsTypeParameter
(#12829)This is due to the corresponding AST shape change.
Migration: Wrap the
name
string within theidentifier
buildermy-babel-codemod.jst.tsTypeParameter(
/* constraint */ undefined,
/* default */ undefined,
+ t.identifier(
name
+ )
) -
Update the
t.tsMappedType
signature (#16733)This is due to the corresponding AST shape change.
// Babel 7
declare function tsMappedType(
typeParameter: TSTypeParameter,
typeAnnotation?: TSType,
nameType?: TSType
): TSMappedType
// Babel 8
declare function tsMappedType(
key: Identifier,
constraint: TSType,
nameType?: TSType,
typeAnnotation?: TSType
): TSMappedTypeMigration: See the example below.
// To create { [P in string as Q]: number }
// Babel 7
t.tsMappedType(
t.tsTypeParameter(t.tsStringKeyword(), undefined, "P"),
t.tsNumberKeyword(),
t.tsTypeReference(t.identifier("Q"))
)
// Babel 8
t.tsMappedType(
t.identifier("P"),
t.tsStringKeyword(),
t.tsTypeReference(t.identifier("Q")),
t.tsNumberKeyword()
)
-
Remove
t.jSX*
andt.tS*
builder aliases (#6989, #15527)Migration: Use
t.jsx*
andt.ts*
instead. For example, replacet.jSXIdentifier("foo")
witht.jsxIdentifier("foo")
. -
Remove
selfClosing
argument fromt.jsxElement
(#14464)- t.jsxElement(openingElement, closingElement, children, selfClosing?: boolean)
+ t.jsxElement(openingElement, closingElement, children)Migration: The
selfClosing
argument was already not used in the builder. You can safely remove it. -
Remove
optional
argument fromt.memberExpression
(#13407)- t.memberExpression(object, property, computed, optional?: boolean)
+ t.memberExpression(object, property, computed)Migration: The
optional
argument was already not used in the builder. You can safely remove it. -
Remove the
Noop
node type (#12361)Migration: There is no generic migration path: you should replace it with the actual node that
Noop
is being used as a placeholder for. If you are depending onNoop
and have no alternative, please open an issue and explain your use case. -
Initialize
indexers
,callProperties
andinternalSlots
in the nodeObjectTypeAnnotation
as an empty array int.objectTypeAnnotation
(#14465)In Babel 7 the builder
t.objectTypeAnnotation
initializes them asnull
, this is inconsistent with how@babel/parser
will parse the Flow object type annotations. In Babel 8 the new default value[]
matches the parser behaviour. -
Reject negative and NaN/infinite numbers from
t.numericLiteral
(#15802)babel-plugin.js// NumericLiterals must be non-negative finite numbers.
t.numericLiteral(-1);Migration: To represent a negative number, use
t.unaryExpression("-", t.numericLiteral(1))
. To represent NaN or Infinity, uset.identifier("NaN")
. To convert a generic numeric value (which could also be negative, NaN, or an inifinity) to the proper AST node, uset.valueToNode(num)
.
@babel/parser
Other than the changes listed below, @babel/parser
is affected by all the AST changes.
-
Align Babel parser error codes between Flow and TypeScript (#13294)
The
error.code
forOptionalBindingPattern
is renamed asPatternIsOptional
. -
Remove
updateContext
field fromtokens[].type
returned from optiontokens: true
(#13768)babel-integration.jsimport { parse } from "@babel/parser";
const { tokens } = parse("a = 42", { tokens: true });
tokens[0].type;
// Babel 7
// { label: "name", updateContext: null, ...other properties }
// Babel 8
// { label: "name", ... other properties }Note that
tokens[].type
is meant to be an opaque object used as an identity for token types, as if it was a symol. Its exact shape is meant to be an internal implementation detail. -
Tokenize private names (
#priv
) as a singleprivateName
token (#13256)babel-integration.jsimport { parse } from "@babel/parser";
const { tokens } = parse("class C { #priv }", { tokens: true });
tokens.filter(t => t.start >= 10 && t.end <= 15) // get tokens for `#priv`
// Babel 7
// [
// Token (#) { value: "#", start: 10, end: 11 },
// Token (name) { value: "priv", start: 11, end: 15 }
// ]
// Babel 8
// [
// Token (privateName) { value: "priv", start: 10, end: 15 }
// ] -
Tokenize template literals as
templateNonTail
andtemplateTail
(#13919)babel-integration.jsimport { parse } from "@babel/parser";
const { tokens } = parse("`head${x}middle${y}tail`", { tokens: true });
console.log(tokens); // print tokens
// Babel 7
// [
// Token (`),
// Token (template) { value: "head" }, Token (${),
// Token (name) { value: "x" }, Token (}),
// Token (template) { value: "middle" }, Token (${),
// Token (name) { value: "y" }, Token (}),
// Token (template) { value: "tail" }
// Token (`)
// ]
// Babel 8
// [
// Token (templateNonTail) { value: "head" },
// Token (name) { value: "x" },
// Token (templateNonTail) { value: "middle" },
// Token (name) { value: "y" },
// Token (templateTail) { value: "tail" }
// ] -
Remove
extra.shorthand
fromObjectProperty
nodes (#16521)Migration: Use
node.shorthand
rather thannode.extra.shorthand
.
@babel/traverse
-
Remove
is
,isnt
,has
,equals
methods fromNodePath
(#16655)Migration: Directly compare properties of
path.node
instead.- functionExpressionPath.equals("id", idNode)
+ functionExpressionPath.node.id === idNode
- functionExpressionPath.is("id")
- functionExpressionPath.has("id")
+ functionExpressionPath.node.id
- functionExpressionPath.has("arguments")
+ !!functionExpressionPath.node.arguments.length
- functionExpressionPath.isnt("async")
+ !functionExpressionPath.node.async -
Remove
hoist
,updateSiblingKeys
,call
,setScope
,resync
,popContext
,pushContext
,setup
,setKey
methods fromNodePath
(#16655)These methods are meant to be private so there is no real migration approach. If your plugin / build is broken by this change, feel free to open an issue and tell us how you use these methods and we can see what we can do after Babel 8 is released.
-
Remove
block
argument fromScope#rename
(#15288)- rename(oldName: string, newName?: string, block?: t.Pattern | t.Scopable)
+ rename(oldName: string, newName?: string)Migration: Instead of passing a different block to
scope.rename()
, directly call.rename()
on the scope corresponding to that block. -
Allow skipped
NodePath
s to be requeued (#13291)NodePath#requeue()
can requeue a skipped NodePath. This is actually a bugfix, but it causes an infinite loop in the temporal dead zone implementation of@babel/plugin-transform-block-scoping
in Babel 7: it may break other plugins as well.Migration: If you want to preserve the old behavior, you can use
NodePath#shouldSkip
to check whether a NodePath has been skipped before callingNodePath#requeue()
. -
Remove
NodePath
methods starting with_
(#16504)_assertUnremoved
_call
_callRemovalHooks
_containerInsert
_containerInsertAfter
_containerInsertBefore
_getKey
_getPattern
_getQueueContexts
_getTypeAnnotation
_markRemoved
_remove
_removeFromScope
_replaceWith
_resolve
_resyncKey
_resyncList
_resyncParent
_resyncRemoved
_verifyNodeListThese methods are meant to be private so there is no real migration approach. If your plugin / build is broken by this change, feel free to open an issue and tell us how you use these methods and we can see what we can do after Babel 8 is released.
@babel/eslint-plugin
-
Remove the
default
property of the exports object (#14180)Migration: This change has no effect if you are using the plugin in your ESLint config. However, if you are extending
@babel/eslint-plugin
, ensure that you obtain exports fromrequire("@babel/eslint-plugin")
rather thanrequire("@babel/eslint-plugin").default
.my-eslint-plugin.cjs// Don't add `.default` after `require()`
const { rules, rulesConfig } = require("@babel/eslint-plugin")
@babel/compat-data
-
Rename stage 4 plugin entries from
proposal-*
totransform-*
inplugins.json
(#14976)This change also affects the
isRequired
function of@babel/helper-compilation-targets
, which receives plugin names as its first parameter.Migration: For example, use
transform-class-properties
rather thanproposal-class-properties
. For a complete list of renamed plugin, see Packages Renames section of Babel 8 migration.my-babel-plugin.jsmodule.exports = api => {
const targets = api.targets();
// The targets have native optional chaining support
// if `transform-optional-chaining` is _not_ required
const optionalChainingSupported = !isRequired(
- "proposal-optional-chaining",
+ "transform-optional-chaining",
targets
);
};
-
Remove
ios_saf
fromdata/native-modules.json
(#15068)Migration: Use
ios
instead.
@babel/helper-replace-supers
-
Remove named export
environmentVisitor
(#15550)Migration: Import it from
@babel/helper-environment-visitor
.- import { environmentVisitor } from "@babel/helper-replace-supers";
+ import environmentVisitor from `@babel/helper-environment-visitor`; -
Remove named export
skipAllButComputedKey
(#15550)Migration: Use
requeueComputedKeyAndDecorators
instead. Find and replace the following import and usagemy-babel7-plugin.jsimport { skipAllButComputedKey } from "@babel/helper-replace-supers";
skipAllButComputedKey(path);to
my-babel8-plugin.jsimport { requeueComputedKeyAndDecorators } from `@babel/helper-environment-visitor`;
path.skip();
requeueComputedKeyAndDecorators(path);
@babel/helper-simple-access
-
Remove the the third parameter
includeUpdateExpression
from the default export (#15550)Note that the Babel 8 behavior is the same as the default Babel 7 behavior (i.e.
includeUpdateExpression: true
).
@babel/highlight
-
Remove the
getChalk
function (https://github.com/babel/babel/pull/15812)If you need to use
chalk
, add it to your dependencies.
Plugin API changes
-
Remove
getModuleName
from plugin pass (#12724)Migration: Use
.file.getModuleName
instead.my-babel-plugin.jsmodule.exports = {
name: "my-babel-plugin",
visitor: {
Identifier(path, pass) {
- const moduleName = pass.getModuleName();
+ const moduleName = pass.file.getModuleName();
}
}
}
-
Remove
addImport
from plugin pass (#15576)This change probably will not affect your plugin as this method is already throwing an error in Babel 7.
Migration: Use
addNamed
oraddDefault
from@babel/helper-module-imports
instead. -
Stop supporting plugin fields as named exports (#15576)
For example, the following file is not a valid plugin anymore:
legacy-babel-plugin.jsexport const name = "legacy-babel-plugin";
export const visitor = {
Identifier() {}
}Migration: Find such patterns and use a default export instead, either exporting a plugin object or a factory function.
my-babel-plugin.cjsexport default {
name: "babel-plugin",
visitor: {
Identifier() {}
}
}