convert @babel/helper-member-expression-to-functions to ts (#12925)

This commit is contained in:
Bogdan Savluk 2021-03-19 12:53:21 +01:00 committed by GitHub
parent beb7cf8b24
commit d1f3d30598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 2 deletions

View File

@ -16,5 +16,8 @@
"author": "Justin Ridgewell <justin@ridgewell.name>",
"dependencies": {
"@babel/types": "workspace:^7.13.0"
},
"devDependencies": {
"@babel/traverse": "workspace:^7.12.17"
}
}

View File

@ -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();
}
@ -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()) {
@ -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)]),

View File

@ -1,3 +1,5 @@
import type { NodePath } from "@babel/traverse";
/**
* Test if a NodePath will be cast to boolean when evaluated.
*

View File

@ -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