Skip to content

Commit

Permalink
fix: if the import is already present, don't add it to the array
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio committed Oct 23, 2020
1 parent 0d48f5b commit b2bf920
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion transforms/v2-to-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b2bf920

Please sign in to comment.