Skip to content

Commit

Permalink
convert @babel/helper-member-expression-to-functions to ts (#12925)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxbodya committed Mar 19, 2021
1 parent beb7cf8 commit d1f3d30
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Expand Up @@ -16,5 +16,8 @@
"author": "Justin Ridgewell <justin@ridgewell.name>",
"dependencies": {
"@babel/types": "workspace:^7.13.0"
},
"devDependencies": {
"@babel/traverse": "workspace:^7.12.17"
}
}
Expand Up @@ -2,6 +2,7 @@ import * as t from "@babel/types";
import { willPathCastToBoolean } from "./util";

class AssignmentMemoiser {
private _map: WeakMap<object, any>;
constructor() {
this._map = new WeakMap();
}
Expand Down Expand Up @@ -84,7 +85,8 @@ const handle = {
// noop.
},

handle(member: t.NodePath<t.Expression>, noDocumentAll: boolean) {
// todo(flow->ts) member:NodePath<t.Expression>, refactor function body to avoid too many typecasts
handle(member: any, noDocumentAll: boolean) {
const { node, parent, parentPath, scope } = member;

if (member.isOptionalMemberExpression()) {
Expand Down Expand Up @@ -350,7 +352,12 @@ const handle = {
const ref = scope.generateUidIdentifierBasedOnNode(node);
scope.push({ id: ref });

value.left = t.assignmentExpression("=", t.cloneNode(ref), value.left);
value.left = t.assignmentExpression(
"=",
t.cloneNode(ref),
// @ts-expect-error todo(flow->ts) value.left is possibly PrivateName, which is not usable here
value.left,
);

parentPath.replaceWith(
t.sequenceExpression([this.set(member, value), t.cloneNode(ref)]),
Expand Down
@@ -1,3 +1,5 @@
import type { NodePath } from "@babel/traverse";

/**
* Test if a NodePath will be cast to boolean when evaluated.
*
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Expand Up @@ -621,6 +621,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@babel/helper-member-expression-to-functions@workspace:packages/babel-helper-member-expression-to-functions"
dependencies:
"@babel/traverse": "workspace:^7.12.17"
"@babel/types": "workspace:^7.13.0"
languageName: unknown
linkType: soft
Expand Down

0 comments on commit d1f3d30

Please sign in to comment.