Huáng Jùnliàng 614b486780
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
2021-08-18 10:28:40 -04:00

32 lines
863 B
JavaScript

import explode from "@babel/helper-explode-assignable-expression";
import { assignmentExpression, sequenceExpression } from "@babel/types";
export default function (opts: { build: Function, operator: string }): Object {
const { build, operator } = opts;
return {
AssignmentExpression(path) {
const { node, scope } = path;
if (node.operator !== operator + "=") return;
const nodes = [];
const exploded = explode(node.left, nodes, this, scope);
nodes.push(
assignmentExpression(
"=",
exploded.ref,
build(exploded.uid, node.right),
),
);
path.replaceWith(sequenceExpression(nodes));
},
BinaryExpression(path) {
const { node } = path;
if (node.operator === operator) {
path.replaceWith(build(node.left, node.right));
}
},
};
}