From 19fc82f993a6e59198615ab85babaa340701ffef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 5 May 2022 16:09:21 -0400 Subject: [PATCH] address review comment --- .../src/util.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/babel-plugin-proposal-destructuring-private/src/util.ts b/packages/babel-plugin-proposal-destructuring-private/src/util.ts index 1c567995a011..66ffbba18b53 100644 --- a/packages/babel-plugin-proposal-destructuring-private/src/util.ts +++ b/packages/babel-plugin-proposal-destructuring-private/src/util.ts @@ -3,8 +3,8 @@ import type { Scope } from "@babel/traverse"; import { types } from "@babel/core"; import type { File } from "@babel/core"; import { buildObjectExcludingKeys } from "@babel/plugin-transform-destructuring"; -import { assignmentExpression, ObjectProperty } from "@babel/types"; const { + assignmentExpression, binaryExpression, conditionalExpression, cloneNode, @@ -49,12 +49,12 @@ function initRestExcludingKeys(pattern: t.LVal): ExcludingKey[] | null { * memoising the computed non-static keys. * * @param {ExcludingKey[]} excludingKeys - * @param {ObjectProperty[]} properties An array of object properties that should be excluded by rest element transform + * @param {t.ObjectProperty[]} properties An array of object properties that should be excluded by rest element transform * @param {Scope} scope Where should we register the memoised id */ function growRestExcludingKeys( excludingKeys: ExcludingKey[], - properties: ObjectProperty[], + properties: t.ObjectProperty[], scope: Scope, ) { if (excludingKeys === null) return; @@ -224,6 +224,7 @@ export function hasPrivateKeys(pattern: t.LVal) { traversePattern(pattern, function* (node) { if (isObjectProperty(node) && isPrivateName(node.key)) { result = true; + // stop the traversal yield; } }).next(); @@ -324,7 +325,7 @@ export function* transformPrivateKeyDestructuring( if (searchPrivateKey.done) { if (restExcludingKeys?.length > 0) { // optimize out the rest element because `objectWithoutProperties` - // always return a new object + // returns a new object // `{ ...z } = babelHelpers.objectWithoutProperties(m, ["x"])` // to // `z = babelHelpers.objectWithoutProperties(m, ["x"])`