Use named imports for babel types (#13685)

* migrate to named babel types imports

* perf: transform babel types import to destructuring

* fix merge errors

* apply plugin to itself
This commit is contained in:
Huáng Jùnliàng
2021-08-18 10:28:40 -04:00
committed by GitHub
parent fc66d4dd05
commit 614b486780
65 changed files with 1283 additions and 787 deletions

View File

@@ -1,7 +1,14 @@
import type { NodePath } from "@babel/traverse";
import nameFunction from "@babel/helper-function-name";
import template from "@babel/template";
import * as t from "@babel/types";
import {
blockStatement,
callExpression,
functionExpression,
isAssignmentPattern,
isRestElement,
returnStatement,
} from "@babel/types";
const buildAnonymousExpressionWrapper = template.expression(`
(function () {
@@ -34,16 +41,14 @@ function classOrObjectMethod(path: NodePath, callId: Object) {
const node = path.node;
const body = node.body;
const container = t.functionExpression(
const container = functionExpression(
null,
[],
t.blockStatement(body.body),
blockStatement(body.body),
true,
);
body.body = [
t.returnStatement(
t.callExpression(t.callExpression(callId, [container]), []),
),
returnStatement(callExpression(callExpression(callId, [container]), [])),
];
// Regardless of whether or not the wrapped function is a an async method
@@ -77,7 +82,7 @@ function plainFunction(path: NodePath, callId: Object, noNewArrows: boolean) {
node.type = "FunctionExpression";
}
const built = t.callExpression(callId, [node]);
const built = callExpression(callId, [node]);
const container = wrapper({
NAME: functionId || null,
REF: path.scope.generateUidIdentifier(functionId ? functionId.name : "ref"),
@@ -85,7 +90,7 @@ function plainFunction(path: NodePath, callId: Object, noNewArrows: boolean) {
PARAMS: node.params.reduce(
(acc, param) => {
acc.done =
acc.done || t.isAssignmentPattern(param) || t.isRestElement(param);
acc.done || isAssignmentPattern(param) || isRestElement(param);
if (!acc.done) {
acc.params.push(path.scope.generateUidIdentifier("x"));