Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve plugins typings (Part 2) #14639

Merged
merged 18 commits into from Jun 18, 2022
Expand Up @@ -3,7 +3,13 @@ import { assignmentExpression, sequenceExpression } from "@babel/types";
import type { Visitor } from "@babel/traverse";
import type * as t from "@babel/types";

export default function (opts: { build: Function; operator: string }) {
export default function (opts: {
build: (
left: t.Expression | t.PrivateName,
right: t.BinaryExpression["right"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just t.Expression?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Yes it is. I tried lowering left to t.Expression when operator is not in but failed.

) => t.Expression;
operator: t.BinaryExpression["operator"];
}) {
const { build, operator } = opts;

const visitor: Visitor = {
Expand Down
Expand Up @@ -14,7 +14,11 @@ export default declare(api => {
build(left, right) {
return t.callExpression(
t.memberExpression(t.identifier("Math"), t.identifier("pow")),
[left, right],
[
// left can be PrivateName only if operator is `"in"`
left as t.Expression,
right,
],
);
},
}),
Expand Down