From b2bf9205b0b49dd0cad76536658fd35d7592ae10 Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 23 Oct 2020 09:38:15 +0200 Subject: [PATCH] fix: if the import is already present, don't add it to the array --- transforms/v2-to-v3.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/transforms/v2-to-v3.ts b/transforms/v2-to-v3.ts index 7c6d726..0cd1d16 100644 --- a/transforms/v2-to-v3.ts +++ b/transforms/v2-to-v3.ts @@ -134,7 +134,10 @@ function migrateTo(root, linguiReactImports, j, lookupImport, newLookupImport, n // we check if the lingui macro import is already present, because if it's already present we just have to push to that import if (imports.paths().length > 0) { imports.forEach((path) => { - path.value.specifiers.push(j.importSpecifier(j.identifier(newLookupImport))); + const foundIndex = path.value.specifiers.findIndex(x => x.imported.name === newLookupImport); + if (foundIndex === -1) { + path.value.specifiers.push(j.importSpecifier(j.identifier(newLookupImport))); + } }); } else { FIRST_IMPORT.insertAfter(