From 70070cd73a6c06ad1aec92b15cc09b82dfb10fc5 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:31:36 -0700 Subject: [PATCH] Process ObjectPattern in getRequireDeclarator --- .../v2-to-v3/modules/getRequireDeclarator.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/transforms/v2-to-v3/modules/getRequireDeclarator.ts b/src/transforms/v2-to-v3/modules/getRequireDeclarator.ts index b7801b383..832011948 100644 --- a/src/transforms/v2-to-v3/modules/getRequireDeclarator.ts +++ b/src/transforms/v2-to-v3/modules/getRequireDeclarator.ts @@ -26,8 +26,20 @@ export const getRequireDeclarator = ( if (declaration.type === "Identifier") return true; const id = declaration.id; - if (id.type !== "Identifier") return true; - if (![v2GlobalName, v2ClientName, v2ClientLocalName].includes(id.name)) return true; + if (id.type === "Identifier") { + if (![v2GlobalName, v2ClientName, v2ClientLocalName].includes(id.name)) return true; + } + if (id.type === "ObjectPattern") { + if ( + !id.properties.some( + (property) => + property.type === "Property" && + property.key.type === "Identifier" && + [v2GlobalName, v2ClientName, v2ClientLocalName].includes(property.key.name) + ) + ) + return true; + } const init = declaration.init; if (!init) return true;