diff --git a/packages/babel-helper-member-expression-to-functions/package.json b/packages/babel-helper-member-expression-to-functions/package.json index 51ce3de0b0..635b5fe628 100644 --- a/packages/babel-helper-member-expression-to-functions/package.json +++ b/packages/babel-helper-member-expression-to-functions/package.json @@ -16,5 +16,8 @@ "author": "Justin Ridgewell ", "dependencies": { "@babel/types": "workspace:^7.13.0" + }, + "devDependencies": { + "@babel/traverse": "workspace:^7.12.17" } } diff --git a/packages/babel-helper-member-expression-to-functions/src/index.js b/packages/babel-helper-member-expression-to-functions/src/index.ts similarity index 97% rename from packages/babel-helper-member-expression-to-functions/src/index.js rename to packages/babel-helper-member-expression-to-functions/src/index.ts index 52a28e8de3..6cdddbefb2 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.ts @@ -2,6 +2,7 @@ import * as t from "@babel/types"; import { willPathCastToBoolean } from "./util"; class AssignmentMemoiser { + private _map: WeakMap; constructor() { this._map = new WeakMap(); } @@ -84,7 +85,8 @@ const handle = { // noop. }, - handle(member: t.NodePath, noDocumentAll: boolean) { + // todo(flow->ts) member:NodePath, 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)]), diff --git a/packages/babel-helper-member-expression-to-functions/src/util.js b/packages/babel-helper-member-expression-to-functions/src/util.ts similarity index 96% rename from packages/babel-helper-member-expression-to-functions/src/util.js rename to packages/babel-helper-member-expression-to-functions/src/util.ts index 107ff410eb..0c77683e4f 100644 --- a/packages/babel-helper-member-expression-to-functions/src/util.js +++ b/packages/babel-helper-member-expression-to-functions/src/util.ts @@ -1,3 +1,5 @@ +import type { NodePath } from "@babel/traverse"; + /** * Test if a NodePath will be cast to boolean when evaluated. * diff --git a/yarn.lock b/yarn.lock index 3760fee11b..59d3a43e96 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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