Skip to content

Commit a11205a

Browse files
committed
Ensure decorators are never imported multiple times
1 parent f4bc070 commit a11205a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"lint:prettier:fix": "prettier --write .",
4444
"lint:ts": "tsc --noEmit",
4545
"test": "yarn build && codemod-cli test && node ./test/run-test.js && yarn clean",
46-
"fixme": "rm codemods.log && yarn build && codemod-cli test; yarn clean",
4746
"update-docs": "codemod-cli update-docs"
4847
},
4948
"dependencies": {

transforms/helpers/import-helper.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,14 @@ export function createDecoratorImportDeclarations(
252252
const existingImport = getExistingImportForPath(root, decoratorPath);
253253
if (existingImport) {
254254
const existingSpecifiers = existingImport.value.specifiers;
255-
if (existingSpecifiers) {
256-
existingImport.value.specifiers = [
257-
...existingSpecifiers,
258-
...specifiers,
259-
];
260-
}
255+
existingImport.value.specifiers = [
256+
...(existingSpecifiers ?? []),
257+
...specifiers,
258+
].filter(
259+
(current, i, array) =>
260+
// Ensure unique specifiers
261+
array.findIndex((s) => s.local?.name === current.local?.name) === i
262+
);
261263
} else {
262264
firstDeclaration.insertBefore(
263265
createImportDeclaration(specifiers, decoratorPath)

0 commit comments

Comments
 (0)